From 8bafce22c99f831b9be3ac896f20923a3f745c77 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Henrik=20tom=20W=C3=B6rden?= <h.tomwoerden@indiscale.com>
Date: Wed, 23 Nov 2022 18:18:10 +0100
Subject: [PATCH] FIX: correct string creation when backrefs are there

---
 src/caoscrawler/identifiable.py |  6 ++++--
 unittests/test_identifiable.py  | 15 +++++++++------
 2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/src/caoscrawler/identifiable.py b/src/caoscrawler/identifiable.py
index 85366531..814c9507 100644
--- a/src/caoscrawler/identifiable.py
+++ b/src/caoscrawler/identifiable.py
@@ -103,8 +103,10 @@ class Identifiable():
         creates a string from the attributes of an identifiable that can be hashed
         String has the form "P<parent>N<name>a:5b:10"
         """
-        rec_string = "P<{}>N<{}>R<{}>".format(identifiable.record_type, identifiable.name,
-                                              identifiable.backrefs)
+        rec_string = "P<{}>N<{}>R<{}>".format(
+            identifiable.record_type,
+            identifiable.name,
+            [Identifiable._value_representation(el) for el in identifiable.backrefs])
         # TODO this structure neglects Properties if multiple exist for the same name
         for pname in sorted(identifiable.properties.keys()):
             rec_string += ("{}:".format(pname) +
diff --git a/unittests/test_identifiable.py b/unittests/test_identifiable.py
index c06ef0ec..e360624f 100644
--- a/unittests/test_identifiable.py
+++ b/unittests/test_identifiable.py
@@ -32,9 +32,9 @@ from caoscrawler.identified_cache import IdentifiedCache
 
 def test_create_hashable_string():
     assert Identifiable._create_hashable_string(
-        Identifiable(name="A", record_type="B")) == "P<B>N<A>"
+        Identifiable(name="A", record_type="B")) == "P<B>N<A>R<[]>"
     assert Identifiable._create_hashable_string(
-        Identifiable(name="A", record_type="B", properties={'a': 5})) == "P<B>N<A>a:5"
+        Identifiable(name="A", record_type="B", properties={'a': 5})) == "P<B>N<A>R<[]>a:5"
     a = Identifiable._create_hashable_string(
         Identifiable(name="A", record_type="B", properties={'a': 4, 'b': 5}))
     b = Identifiable._create_hashable_string(
@@ -43,21 +43,24 @@ def test_create_hashable_string():
     assert (
         Identifiable._create_hashable_string(
             Identifiable(name="A", record_type="B", properties={'a': db.Record(id=12)})
-        ) == "P<B>N<A>a:12")
+        ) == "P<B>N<A>R<[]>a:12")
     a = Identifiable._create_hashable_string(
         Identifiable(name="A", record_type="B", properties={'a': [db.Record(id=12)]}))
-    assert (a == "P<B>N<A>a:[12]")
+    assert (a == "P<B>N<A>R<[]>a:[12]")
     assert (Identifiable._create_hashable_string(
-        Identifiable(name="A", record_type="B", properties={'a': [12]})) == "P<B>N<A>a:[12]")
+        Identifiable(name="A", record_type="B", properties={'a': [12]})) == "P<B>N<A>R<[]>a:[12]")
     assert (
         Identifiable._create_hashable_string(
             Identifiable(name="A", record_type="B", properties={'a': [db.Record(id=12), 11]})
-        ) == "P<B>N<A>a:[12, 11]")
+        ) == "P<B>N<A>R<[]>a:[12, 11]")
     assert (
         Identifiable._create_hashable_string(
             Identifiable(record_type="B", properties={'a': [db.Record()]})
         ) != Identifiable._create_hashable_string(
             Identifiable(record_type="B", properties={'a': [db.Record()]})))
+    assert Identifiable._create_hashable_string(
+        Identifiable(name="A", record_type="B", backrefs=[123, db.Entity(id=124)],
+                     properties={'a': 5})) == "P<B>N<A>R<['123', '124']>a:5"
 
 
 def test_name():
-- 
GitLab