aplbrain / grand

Your favorite Python graph libraries, scalable and interoperable. Graph databases in memory, and familiar graph APIs for cloud databases.
Apache License 2.0
80 stars 6 forks source link

SQLBackend all_edges_as_iterable accesses _node_table instead of _edge_table resulting in KeyError: 'Source' #55

Closed mrckzgl closed 3 months ago

mrckzgl commented 3 months ago

Just a quick find which results in:

  File ".local/lib/python3.10/site-packages/grand/backends/_sqlbackend.py", line 309, in all_edges_as_iterable
    self._node_table.c[self._edge_source_key],
  File ".local/lib/python3.10/site-packages/sqlalchemy/sql/base.py", line 1608, in __getitem__
    return self._index[key][1]
KeyError: 'Source'

This: https://github.com/aplbrain/grand/blob/e71be46259fde37136cff0bdad3f998787f92cf3/grand/backends/_sqlbackend.py#L297C9-L317

should access self._edge_table instead of self._node_table.

best

mrckzgl commented 3 months ago

Additionally when fixing this, I am getting:

  File ".local/lib/python3.10/site-packages/sqlalchemy/sql/base.py", line 280, in _generative
    x = fn(self, *args, **kw)
  File ".local/lib/python3.10/site-packages/sqlalchemy/sql/selectable.py", line 5915, in with_only_columns
    for c in coercions._expression_collection_was_a_list(
  File ".local/lib/python3.10/site-packages/sqlalchemy/sql/coercions.py", line 152, in _expression_collection_was_a_list
    raise exc.ArgumentError(
sqlalchemy.exc.ArgumentError: The "entities" argument to Select.with_only_columns(), when referring to a sequence of items, is now passed as a series of positional elements, rather than as a list. 

Fix is to use:

sql = self._node_table.select().with_only_columns(*columns)
j6k4m8 commented 3 months ago

Thank you for reporting this, @mrckzgl! Looks like a recent regression, really appreciate you finding a fix too!

j6k4m8 commented 3 months ago

Resolved in v0.5.2 (also live on PyPI) — thanks again for the notice! Give a holler if this doesn't fix for you!