From 9f6aa44109fddda79a2710bccabe88bf86be6093 Mon Sep 17 00:00:00 2001 From: Antonin Blot Date: Tue, 19 Mar 2024 16:06:42 +0000 Subject: [PATCH] [feature] crash `update_entity` if reserved fields are used as attributes. --- CHANGELOG.md | 7 +++++++ flexiznam/main.py | 6 +++++- setup.py | 2 +- tests/test_components/test_main.py | 12 ++++++++++++ 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2933132..293696c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/flexiznam/main.py b/flexiznam/main.py index cc21319..e0e1e97 100755 --- a/flexiznam/main.py +++ b/flexiznam/main.py @@ -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, diff --git a/setup.py b/setup.py index f6f0f42..7e187ab 100755 --- a/setup.py +++ b/setup.py @@ -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", diff --git a/tests/test_components/test_main.py b/tests/test_components/test_main.py index 252a588..468ea68 100644 --- a/tests/test_components/test_main.py +++ b/tests/test_components/test_main.py @@ -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", + }, + )