Skip to content

Commit

Permalink
Merge pull request #213 from singnet/senna-hotfix-9
Browse files Browse the repository at this point in the history
[HOTFIX] Fix ill-committed  update in get_atom()
  • Loading branch information
andre-senna authored Sep 10, 2024
2 parents 3917a45 + 7fa632f commit 6c338f9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
17 changes: 9 additions & 8 deletions hyperon_das_atomdb/adapters/redis_mongo_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -748,25 +748,26 @@ def get_link_type(self, link_handle: str) -> str | None:
return document[FieldNames.TYPE_NAME]

def _get_atom(self, handle: str) -> AtomT | None:
return self._retrieve_document(handle)
return self.get_atom_as_dict(handle)

def get_atom_type(self, handle: str) -> str | None:
atom = self._retrieve_document(handle)
if atom is None:
return None
return atom[FieldNames.TYPE_NAME]

def get_atom_as_dict(self, handle: str, arity: int | None = 0) -> dict[str, Any]:
answer = {}
def get_atom_as_dict(self, handle: str, arity: int | None = 0) -> AtomT:
document = self._retrieve_document(handle)
if document:
answer["handle"] = document[FieldNames.ID_HASH]
answer["type"] = document[FieldNames.TYPE_NAME]
document["handle"] = document[FieldNames.ID_HASH]
document["type"] = document[FieldNames.TYPE_NAME]
if "targets" in document:
answer["targets"] = document["targets"]
document["targets"] = document["targets"]
else:
answer["name"] = document["name"]
return answer
document["name"] = document["name"]
return document
else:
return None

def count_atoms(self, parameters: dict[str, Any] | None = None) -> dict[str, int]:
atom_count = self.mongo_atoms_collection.estimated_document_count()
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -779,8 +779,8 @@ def test_get_atom_as_dict_none(self, database, request):
db: AtomDB = request.getfixturevalue(database)
atom_node = db.get_atom_as_dict("handle")
atom_link = db.get_atom_as_dict("handle")
assert atom_node == {}
assert atom_link == {}
assert atom_node is None
assert atom_link is None

@pytest.mark.parametrize("database", ["redis_mongo_db", "in_memory_db"])
def test_get_atom_as_dict_exceptions(self, database, request):
Expand Down

0 comments on commit 6c338f9

Please sign in to comment.