Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 7 additions & 14 deletions application/database/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -1174,12 +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 internal_link.cre == cre.id:
# 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
Expand All @@ -1196,17 +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))
)
else:
raise ValueError(
f"Received an unexpected link type {link_type} in internal link between {linked_cre.name} and {cre.name}"
)
else: # 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))
)
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)))
return links

def __make_cre_links(
Expand Down
2 changes: 1 addition & 1 deletion application/tests/cre_main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
[
Expand Down
1 change: 1 addition & 0 deletions application/tests/db_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,7 @@ def test_get_CREs(self) -> None:
)
)
collection.session.commit()
self.maxDiff = None

# we can retrieve children cres
self.assertEqual(
Expand Down