From ce066539bbd7c0e1c0e6b8a0becd8c37dd96bd54 Mon Sep 17 00:00:00 2001 From: Enya-Yx Date: Fri, 19 Aug 2022 14:50:49 +0800 Subject: [PATCH 1/3] Fix graph edge errors when calling sql APIs --- registry/sql-registry/registry/db_registry.py | 4 +++- registry/sql-registry/registry/models.py | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/registry/sql-registry/registry/db_registry.py b/registry/sql-registry/registry/db_registry.py index 4361f3e91..668bd2fe7 100644 --- a/registry/sql-registry/registry/db_registry.py +++ b/registry/sql-registry/registry/db_registry.py @@ -405,16 +405,18 @@ def _fill_entity(self, e: Entity) -> Entity: return e def _get_edges(self, ids: list[UUID], types: list[RelationshipType] = []) -> list[Edge]: - if not ids or not types: + if not ids: return [] sql = fr"""select edge_id, from_id, to_id, conn_type from edges where from_id in %(ids)s and to_id in %(ids)s""" + types = [ str(t) for t in types] if len(types) > 0: sql = fr"""select edge_id, from_id, to_id, conn_type from edges where conn_type in %(types)s and from_id in %(ids)s and to_id in %(ids)s""" + rows = self.conn.query(sql, { "ids": tuple([str(id) for id in ids]), "types": tuple([str(t) for t in types]), diff --git a/registry/sql-registry/registry/models.py b/registry/sql-registry/registry/models.py index f032099af..f12defa99 100644 --- a/registry/sql-registry/registry/models.py +++ b/registry/sql-registry/registry/models.py @@ -117,6 +117,15 @@ class RelationshipType(Enum): Produces = 4 + def __str__(self): + return { + RelationshipType.Contains: "Contains", + RelationshipType.BelongsTo: "BelongsTo", + RelationshipType.Consumes: "Consumes", + RelationshipType.Produces: "Produces", + }[self] + + class ToDict(ABC): """ This ABC is used to convert object to dict, then JSON. From 493c6f0aad6e52a1c19dad57da94075ebf5a9c1f Mon Sep 17 00:00:00 2001 From: Enya-Yx Date: Tue, 23 Aug 2022 15:51:03 +0800 Subject: [PATCH 2/3] minor fix --- registry/sql-registry/registry/db_registry.py | 3 +-- registry/sql-registry/registry/models.py | 10 ---------- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/registry/sql-registry/registry/db_registry.py b/registry/sql-registry/registry/db_registry.py index 668bd2fe7..58f4b98db 100644 --- a/registry/sql-registry/registry/db_registry.py +++ b/registry/sql-registry/registry/db_registry.py @@ -410,7 +410,6 @@ def _get_edges(self, ids: list[UUID], types: list[RelationshipType] = []) -> lis sql = fr"""select edge_id, from_id, to_id, conn_type from edges where from_id in %(ids)s and to_id in %(ids)s""" - types = [ str(t) for t in types] if len(types) > 0: sql = fr"""select edge_id, from_id, to_id, conn_type from edges where conn_type in %(types)s @@ -419,7 +418,7 @@ def _get_edges(self, ids: list[UUID], types: list[RelationshipType] = []) -> lis rows = self.conn.query(sql, { "ids": tuple([str(id) for id in ids]), - "types": tuple([str(t) for t in types]), + "types": tuple([t.name for t in types]), }) return list([_to_type(row, Edge) for row in rows]) diff --git a/registry/sql-registry/registry/models.py b/registry/sql-registry/registry/models.py index f12defa99..5dbe8f4ae 100644 --- a/registry/sql-registry/registry/models.py +++ b/registry/sql-registry/registry/models.py @@ -116,16 +116,6 @@ class RelationshipType(Enum): Consumes = 3 Produces = 4 - - def __str__(self): - return { - RelationshipType.Contains: "Contains", - RelationshipType.BelongsTo: "BelongsTo", - RelationshipType.Consumes: "Consumes", - RelationshipType.Produces: "Produces", - }[self] - - class ToDict(ABC): """ This ABC is used to convert object to dict, then JSON. From 06ddafbe4017aa7871a117be7b39936a2c26d8a4 Mon Sep 17 00:00:00 2001 From: Enya-Yx Date: Tue, 23 Aug 2022 15:53:41 +0800 Subject: [PATCH 3/3] minor change --- registry/sql-registry/registry/models.py | 1 + 1 file changed, 1 insertion(+) diff --git a/registry/sql-registry/registry/models.py b/registry/sql-registry/registry/models.py index 5dbe8f4ae..f032099af 100644 --- a/registry/sql-registry/registry/models.py +++ b/registry/sql-registry/registry/models.py @@ -116,6 +116,7 @@ class RelationshipType(Enum): Consumes = 3 Produces = 4 + class ToDict(ABC): """ This ABC is used to convert object to dict, then JSON.