Skip to content

Commit

Permalink
[feature] crash update_entity if reserved fields are used as attrib…
Browse files Browse the repository at this point in the history
…utes.
  • Loading branch information
Antonin Blot committed Mar 19, 2024
1 parent 53523e4 commit 9f6aa44
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Change log


## v0.3.10

### Main changes

- Make `update_entity` safer by crashing if reserved fields are used as attributes.

## v0.3.9

### Main changes
Expand Down
6 changes: 5 additions & 1 deletion flexiznam/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,11 @@ def update_entity(
raise AttributeError("`mode` must be `overwrite` or `update`")
if id is None:
id = entity["id"]

for attr in full_attributes:
if attr in entity:
raise FlexilimsError(
"Attribute `%s` is a flexilims reserved keyword" % attr
)
rep = flexilims_session.update_one(
id=id,
datatype=datatype,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name="flexiznam",
version="v0.3.9",
version="v0.3.10",
url="https://github.com/znamlab/flexznam",
license="MIT",
author="Antonin Blot",
Expand Down
12 changes: 12 additions & 0 deletions tests/test_components/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,3 +429,15 @@ def test_update_entity(flm_sess):
datatype="dataset", name=dataset_name, flexilims_session=flm_sess
)
assert repr(new_entity) == repr(original_entity)
with pytest.raises(FlexilimsError) as err:
flz.update_entity(
"dataset",
name=dataset_name,
flexilims_session=flm_sess,
attributes={
"path": "new/path",
"dataset_type": "scanimage",
"project": "random",
"createdBy": "BAD",
},
)

0 comments on commit 9f6aa44

Please sign in to comment.