From e58896a3fe14f6174cc35c959c4b228a633cde27 Mon Sep 17 00:00:00 2001 From: Spyros Date: Tue, 12 Nov 2024 14:19:55 +0000 Subject: [PATCH] fix broken change where a cre would be added twice --- application/database/db.py | 13 +++++-------- application/tests/cre_main_test.py | 2 +- application/tests/db_test.py | 1 + 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/application/database/db.py b/application/database/db.py index b755ce09..86a09b6f 100644 --- a/application/database/db.py +++ b/application/database/db.py @@ -1174,11 +1174,12 @@ def __make_cre_internal_links(self, cre: CRE) -> List[cre_defs.Link]: ) for internal_link in internal_links: + linked_cre_query = self.session.query(CRE) link_type = cre_defs.LinkTypes.from_str(internal_link.type) if internal_link.cre == cre.id: - # if we are the lower cre in this relationship, we need to flip the "Contains" linktypes + # if we are the lower cre in this relationship, we need to flip the "Contains" linktypes linked_cre = linked_cre_query.filter( CRE.id == internal_link.group ).first() # get the higher cre so we can add the link @@ -1195,14 +1196,10 @@ def __make_cre_internal_links(self, cre: CRE) -> List[cre_defs.Link]: links.append( cre_defs.Link(ltype=link_type, document=CREfromDB(linked_cre)) ) - + continue # if we are are the higher cre then we don't need to do anything, relationship types are always "higher"->"lower" - linked_cre = linked_cre_query.filter( - CRE.id == internal_link.cre - ).first() - links.append( - cre_defs.Link(ltype=link_type, document=CREfromDB(linked_cre)) - ) + linked_cre = linked_cre_query.filter(CRE.id == internal_link.cre).first() + links.append(cre_defs.Link(ltype=link_type, document=CREfromDB(linked_cre))) return links def __make_cre_links( diff --git a/application/tests/cre_main_test.py b/application/tests/cre_main_test.py index 6306a8b0..a5c43119 100644 --- a/application/tests/cre_main_test.py +++ b/application/tests/cre_main_test.py @@ -262,7 +262,7 @@ def test_register_cre(self) -> None: c_lower = self.collection.get_CREs(cre_lower.id)[0] c_equal = self.collection.get_CREs(cre_equal.id)[0] retrieved_cre = self.collection.get_CREs(cre.id)[0] - + self.maxDiff = None self.assertCountEqual( c_higher.links, [ diff --git a/application/tests/db_test.py b/application/tests/db_test.py index 1db0545a..1d13bd0b 100644 --- a/application/tests/db_test.py +++ b/application/tests/db_test.py @@ -568,6 +568,7 @@ def test_get_CREs(self) -> None: ) ) collection.session.commit() + self.maxDiff = None # we can retrieve children cres self.assertEqual(