diff --git a/CHANGELOG.md b/CHANGELOG.md index b3fd446..d84db9b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # CHANGELOG +## **0.5.2** (June 4, 2024) + +- Bugfixes: + - Fixes SQLBackend mistakenly referencing Nodes table for enumeration of Edges (#55, #56) + ## **0.5.1** (May 13, 2024) - Bugfixes: diff --git a/grand/__init__.py b/grand/__init__.py index 5b8c0fb..d17be25 100644 --- a/grand/__init__.py +++ b/grand/__init__.py @@ -10,7 +10,7 @@ _DEFAULT_BACKEND = NetworkXBackend -__version__ = "0.5.1" +__version__ = "0.5.2" class Graph: diff --git a/grand/backends/_sqlbackend.py b/grand/backends/_sqlbackend.py index 8a6591d..2f71493 100644 --- a/grand/backends/_sqlbackend.py +++ b/grand/backends/_sqlbackend.py @@ -306,14 +306,14 @@ def all_edges_as_iterable(self, include_metadata: bool = False) -> Generator: """ columns = [ - self._node_table.c[self._edge_source_key], - self._node_table.c[self._edge_target_key], + self._edge_table.c[self._edge_source_key], + self._edge_table.c[self._edge_target_key], ] if include_metadata: - columns.append(self._node_table.c["_metadata"]) + columns.append(self._edge_table.c["_metadata"]) - sql = self._node_table.select().with_only_columns(columns) + sql = self._edge_table.select().with_only_columns(*columns) return self._connection.execute(sql).fetchall() def get_node_by_id(self, node_name: Hashable): @@ -676,4 +676,4 @@ def commit(self): self._connection.commit() def close(self): - self._connection.close() \ No newline at end of file + self._connection.close() diff --git a/grand/backends/test_backends.py b/grand/backends/test_backends.py index 5b345e6..cb0d098 100644 --- a/grand/backends/test_backends.py +++ b/grand/backends/test_backends.py @@ -131,6 +131,7 @@ ), ) + # @pytest.mark.parametrize("backend", backend_test_params) class TestBackendPersistence: def test_sqlite_persistence(self): @@ -138,23 +139,22 @@ def test_sqlite_persistence(self): return dbpath = "grand_peristence_test_temp.db" - url = "sqlite:///"+dbpath + url = "sqlite:///" + dbpath - #arrange + # arrange backend = SQLBackend(db_url=url, directed=True) - node0 = backend.add_node("A",{"foo":"bar"}) + node0 = backend.add_node("A", {"foo": "bar"}) backend.commit() backend.close() - #act + # act backend = SQLBackend(db_url=url, directed=True) nodes = list(backend.all_nodes_as_iterable()) - #assert + # assert assert node0 in nodes - #cleanup + # cleanup os.remove(dbpath) - @pytest.mark.parametrize("backend", backend_test_params) class TestBackend: def test_can_create(self, backend): @@ -344,6 +344,12 @@ def test_can_get_edge_metadata(self, backend): G.nx.add_edge("foo", "bar", baz=True) assert list(G.nx.edges(data=True)) == [("foo", "bar", {"baz": True})] + def test_can_get_edges(self, backend): + backend, kwargs = backend + G = Graph(backend=backend(**kwargs)) + G.nx.add_edge("foo", "bar", baz=True) + assert list(G.backend.all_edges_as_iterable()) == [("foo", "bar")] + def test_edge_dne_raises(self, backend): backend, kwargs = backend G = Graph(backend=backend(**kwargs)) diff --git a/setup.py b/setup.py index e29231e..3050951 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ setuptools.setup( name="grand-graph", - version="0.5.1", + version="0.5.2", author="Jordan Matelsky", author_email="opensource@matelsky.com", description="Graph database wrapper for non-graph datastores",