diff --git a/CHANGELOG.md b/CHANGELOG.md index cde38fb0f2efd99856f677fc41e66252d1a43e23..6bab1031394c51f8988dc25c4947c84fd2644b3d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Query generation when there are spaces or `'` in RecordType or Identifiable names - usage of ID when looking for identified records +- [#41](https://gitlab.com/caosdb/caosdb-crawler/-/issues/41) ### Security ### diff --git a/src/caoscrawler/identifiable_adapters.py b/src/caoscrawler/identifiable_adapters.py index 245927e7313ca31a78bbe9b54dcb23ddfb837346..a65af7d0b93f2d622190b88f9f176cd08af4bca4 100644 --- a/src/caoscrawler/identifiable_adapters.py +++ b/src/caoscrawler/identifiable_adapters.py @@ -194,12 +194,14 @@ identifiabel, identifiable and identified record) for a Record. property_name_list_B = [] identifiable_props = {} identifiable_backrefs = [] + name_is_identifying_property = False if registered_identifiable is not None: # fill the values: for prop in registered_identifiable.properties: if prop.name == "name": # The name can be an identifiable, but it isn't a property + name_is_identifying_property = True continue # problem: what happens with multi properties? # case A: in the registered identifiable @@ -247,7 +249,7 @@ identifiabel, identifiable and identified record) for a Record. record_id=record.id, record_type=(registered_identifiable.parents[0].name if registered_identifiable else None), - name=record.name, + name=record.name if name_is_identifying_property else None, properties=identifiable_props, path=record.path, backrefs=identifiable_backrefs diff --git a/src/doc/how-to-upgrade.md b/src/doc/how-to-upgrade.md index 4efc78280ca9ddbb893f166ee3530b3363684081..2e26531d27a1cb038afa1b487007157b532a6fb7 100644 --- a/src/doc/how-to-upgrade.md +++ b/src/doc/how-to-upgrade.md @@ -1,7 +1,12 @@ # How to upgrade +## 0.5.x to 0.6.0 +[#41](https://gitlab.com/caosdb/caosdb-crawler/-/issues/41) was fixed. This +means that you previously used the name of Entities as an identifying +property without adding it to the identifiable definition, you now need to +add 'name' explicitly. -## 0.4.0 to 0.5.0 +## 0.4.x to 0.5.0 The crawler was split into two modules: the scanner and the crawler. The scanner creates a Record structure from the data and the crawler synchronizes this with the server. Due to this change you should: diff --git a/unittests/test_crawler.py b/unittests/test_crawler.py index f28cd897fe9f1c31b1d13648f19356066a58ed8e..dc53cb099eb5e4b225b13461176504a003f2d2ba 100644 --- a/unittests/test_crawler.py +++ b/unittests/test_crawler.py @@ -228,7 +228,7 @@ def crawler_mocked_identifiable_retrieve(): # TODO use minimal setup # mock retrieval of registered identifiabls: return Record with just a parent crawler.identifiableAdapter.get_registered_identifiable = Mock( - side_effect=lambda x: db.Record().add_parent(x.parents[0].name)) + side_effect=lambda x: db.Record().add_parent(x.parents[0].name).add_property(name='name')) # Simulate remote server content by using the names to identify records # There is only a single known Record with name A @@ -360,9 +360,9 @@ def test_has_missing_object_in_references(): # There are only two known Records with name A and B crawler.identifiableAdapter.get_registered_identifiable = Mock(side_effect=partial( basic_retrieve_by_name_mock_up, known={"C": db.Record(name="C").add_parent("RTC") - .add_property("d"), + .add_property("d").add_property("name"), "D": db.Record(name="D").add_parent("RTD") - .add_property("d").add_property("e"), + .add_property("d").add_property("e").add_property("name"), })) # one reference with id -> check @@ -615,12 +615,12 @@ def crawler_mocked_for_backref_test(): def get_reg_ident(x): if x.parents[0].name == "C": return db.Record().add_parent(x.parents[0].name).add_property( - "is_referenced_by", value=["BR"]) + "is_referenced_by", value=["BR"]).add_property("name") elif x.parents[0].name == "D": return db.Record().add_parent(x.parents[0].name).add_property( - "is_referenced_by", value=["BR", "BR2"]) + "is_referenced_by", value=["BR", "BR2"]).add_property("name") else: - return db.Record().add_parent(x.parents[0].name) + return db.Record().add_parent(x.parents[0].name).add_property("name") crawler.identifiableAdapter.get_registered_identifiable = Mock(side_effect=get_reg_ident) # Simulate remote server content by using the names to identify records diff --git a/unittests/test_identifiable_adapters.py b/unittests/test_identifiable_adapters.py index 5c338f0e37dea0d3d502fc9931ad421b72944699..268b9800ddf1ef1688386f394ec1c6c7eb3e3912 100644 --- a/unittests/test_identifiable_adapters.py +++ b/unittests/test_identifiable_adapters.py @@ -120,6 +120,19 @@ def test_load_from_yaml_file(): assert project_i.get_property("title") is not None +def test_non_default_name(): + ident = CaosDBIdentifiableAdapter() + ident.register_identifiable( + "Person", db.RecordType() + .add_parent(name="Person") + .add_property(name="last_name")) + identifiable = ident.get_identifiable(db.Record(name="don't touch it") + .add_parent("Person") + .add_property(name="last_name", value='Tom') + ) + assert identifiable.name is None + + def test_convert_value(): # test that string representation of objects stay unchanged. No stripping or so. class A():