From 0d79dd38ef6486cc19b77bdce185bfb03c68c646 Mon Sep 17 00:00:00 2001 From: erhe Date: Fri, 13 Sep 2024 10:17:22 +0200 Subject: [PATCH 1/3] do not expose restricted projections --- source/ftrack_api/entity/factory.py | 3 +++ test/unit/test_session.py | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/source/ftrack_api/entity/factory.py b/source/ftrack_api/entity/factory.py index 195ebd5d..67a07997 100644 --- a/source/ftrack_api/entity/factory.py +++ b/source/ftrack_api/entity/factory.py @@ -63,6 +63,9 @@ def create(self, schema, bases=None): data_type = fragment.get("type", ftrack_api.symbol.NOT_SET) + if fragment.get("restricted_projection", False): + continue + if data_type is not ftrack_api.symbol.NOT_SET: if data_type in ( "string", diff --git a/test/unit/test_session.py b/test/unit/test_session.py index 8735aab9..b59b739c 100644 --- a/test/unit/test_session.py +++ b/test/unit/test_session.py @@ -1488,3 +1488,13 @@ def test_custom_headers_session(): "abc" in new_session._request.headers.keys(), new_session._request.headers["abc"] == "def", ) + + +def test_restricted_projections(mocked_schema_session): + """Ensure properties marked with restricted_projection are not added as properties""" + entity = mocked_schema_session.create( + "RestrictedProjection", {"id": str(uuid.uuid4())} + ) + + # Ensure the restricted property is not present + assert {"id", "normal"} == set([prop.name for prop in entity.attributes]) From 5681b387d5a3aa8738aaf5c4a4059eccf6d4d47b Mon Sep 17 00:00:00 2001 From: erhe Date: Fri, 13 Sep 2024 10:40:51 +0200 Subject: [PATCH 2/3] updated fixture. --- test/unit/conftest.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/unit/conftest.py b/test/unit/conftest.py index cb3cdecf..50c69fe1 100644 --- a/test/unit/conftest.py +++ b/test/unit/conftest.py @@ -531,6 +531,19 @@ def mocked_schemas(): "required": ["id"], "default_projections": ["id"], }, + { + "id": "RestrictedProjection", + "type": "object", + "properties": { + "id": {"type": "string"}, + "restricted": {"type": "string", "restricted_projection": True}, + "normal": {"type": "string", "restricted_projection": False}, + }, + "immutable": ["id"], + "primary_key": ["id"], + "required": ["id"], + "default_projections": ["id"], + }, ] From 88dcbb1ed783888d9e0329ecbadead7be7e29e0c Mon Sep 17 00:00:00 2001 From: erhe Date: Fri, 13 Sep 2024 11:07:57 +0200 Subject: [PATCH 3/3] update hash --- test/unit/test_session.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unit/test_session.py b/test/unit/test_session.py index b59b739c..c587e220 100644 --- a/test/unit/test_session.py +++ b/test/unit/test_session.py @@ -1002,7 +1002,7 @@ def test_correct_file_type_on_sequence_component(session): def test_read_schemas_from_cache(session, temporary_valid_schema_cache): """Read valid content from schema cache.""" - expected_hash = "a98d0627b5e33966e43e1cb89b082db7" + expected_hash = "c8f8bdc59c415a5a96339647e45b751b" schemas, hash_ = session._read_schemas_from_cache(temporary_valid_schema_cache) @@ -1019,7 +1019,7 @@ def test_fail_to_read_schemas_from_invalid_cache( def test_write_schemas_to_cache(session, temporary_valid_schema_cache): """Write valid content to schema cache.""" - expected_hash = "a98d0627b5e33966e43e1cb89b082db7" + expected_hash = "c8f8bdc59c415a5a96339647e45b751b" schemas, _ = session._read_schemas_from_cache(temporary_valid_schema_cache) session._write_schemas_to_cache(schemas, temporary_valid_schema_cache)