-
Notifications
You must be signed in to change notification settings - Fork 76
fix: can't query vertex with number vertex id #329
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,7 +32,7 @@ dependencies = [ | |
| "requests", | ||
| "setuptools", | ||
| "urllib3", | ||
| "rich", | ||
| "rich" | ||
| ] | ||
|
|
||
| [project.urls] | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -45,21 +45,21 @@ def addVertices(self, input_data): | |||||
| return [VertexData({"id": item}) for item in response] | ||||||
| return None | ||||||
|
|
||||||
| @router.http("PUT", 'graph/vertices/"{vertex_id}"?action=append') | ||||||
| @router.http("PUT", 'graph/vertices/{vertex_id}?action=append') | ||||||
| def appendVertex(self, vertex_id, properties): # pylint: disable=unused-argument | ||||||
| data = {"properties": properties} | ||||||
| if response := self._invoke_request(data=json.dumps(data)): | ||||||
| return VertexData(response) | ||||||
| return None | ||||||
|
|
||||||
| @router.http("PUT", 'graph/vertices/"{vertex_id}"?action=eliminate') | ||||||
| @router.http("PUT", 'graph/vertices/{vertex_id}?action=eliminate') | ||||||
| def eliminateVertex(self, vertex_id, properties): # pylint: disable=unused-argument | ||||||
| data = {"properties": properties} | ||||||
| if response := self._invoke_request(data=json.dumps(data)): | ||||||
| return VertexData(response) | ||||||
| return None | ||||||
|
|
||||||
| @router.http("GET", 'graph/vertices/"{vertex_id}"') | ||||||
| @router.http("GET", 'graph/vertices/{vertex_id}') | ||||||
| def getVertexById(self, vertex_id): # pylint: disable=unused-argument | ||||||
| if response := self._invoke_request(): | ||||||
| return VertexData(response) | ||||||
|
|
@@ -101,7 +101,7 @@ def getVertexByCondition(self, label="", limit=0, page=None, properties=None): | |||||
| return [VertexData(item) for item in response["vertices"]] | ||||||
| return None | ||||||
|
|
||||||
| @router.http("DELETE", 'graph/vertices/"{vertex_id}"') | ||||||
| @router.http("DELETE", 'graph/vertices/{vertex_id}') | ||||||
| def removeVertexById(self, vertex_id): # pylint: disable=unused-argument | ||||||
| return self._invoke_request() | ||||||
|
|
||||||
|
|
@@ -200,8 +200,10 @@ def getVerticesById(self, vertex_ids) -> list[VertexData] | None: | |||||
| if not vertex_ids: | ||||||
| return [] | ||||||
| path = "traversers/vertices?" | ||||||
| for vertex_id in vertex_ids: | ||||||
| path += f'ids="{vertex_id}"&' # pylint: disable=consider-using-join | ||||||
| quoted_vertex_ids = map(json.dumps, vertex_ids) | ||||||
|
|
||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| for vertex_id in quoted_vertex_ids: | ||||||
| path += f'ids={vertex_id}&' # pylint: disable=consider-using-join | ||||||
| path = path.rstrip("&") | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
def test_get_vertices_by_number_id(self):
vertex = self.graph.addVertex("department", {"name": "DeptA", "headcount": 10, "floor": 1})
result = self.graph.getVerticesById([vertex.id])
self.assertIsNotNone(result)
self.assertEqual(result[0].id, vertex.id) |
||||||
| if response := self._sess.request(path): | ||||||
| return [VertexData(item) for item in response["vertices"]] | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ | |
| from ..client_utils import ClientUtils | ||
|
|
||
|
|
||
|
|
||
| class TestGraphManager(unittest.TestCase): | ||
| client = None | ||
| graph = None | ||
|
|
@@ -57,17 +58,33 @@ def test_append_vertex(self): | |
| appended_vertex = self.graph.appendVertex(vertex.id, {"city": "Beijing"}) | ||
| self.assertEqual(appended_vertex.properties["city"], "Beijing") | ||
|
|
||
| def test_append_vertex_with_number_id(self): | ||
| vertex = self.graph.addVertex("department", {"name": "DepartmentA", "headcount": 10, "floor": 1}) | ||
| appended_vertex = self.graph.appendVertex(vertex.id, {"headcount": 15}) | ||
| self.assertEqual(appended_vertex.properties["headcount"], 15) | ||
|
|
||
| def test_eliminate_vertex(self): | ||
| vertex = self.graph.addVertex("person", {"name": "marko", "age": 29, "city": "Beijing"}) | ||
| self.graph.eliminateVertex(vertex.id, {"city": "Beijing"}) | ||
| eliminated_vertex = self.graph.getVertexById(vertex.id) | ||
| self.assertIsNone(eliminated_vertex.properties.get("city")) | ||
|
|
||
| def test_eliminate_vertex_with_number_id(self): | ||
| vertex = self.graph.addVertex("department", {"name": "DepartmentA", "headcount": 10, "floor": 1}) | ||
| self.graph.eliminateVertex(vertex.id, {"floor": 1}) | ||
| eliminated_vertex = self.graph.getVertexById(vertex.id) | ||
| self.assertIsNone(eliminated_vertex.properties.get("floor")) | ||
|
|
||
| def test_get_vertex_by_id(self): | ||
| vertex = self.graph.addVertex("person", {"name": "Alice", "age": 20}) | ||
| retrieved_vertex = self.graph.getVertexById(vertex.id) | ||
| self.assertEqual(retrieved_vertex.id, vertex.id) | ||
|
|
||
| def test_get_vertex_by_number_id(self): | ||
| vertex = self.graph.addVertex("department", {"name": "DepartmentA", "headcount": 10, "floor": 1}) | ||
| retrieved_vertex = self.graph.getVertexById(vertex.id) | ||
| self.assertEqual(retrieved_vertex.id, vertex.id) | ||
|
|
||
| def test_get_vertex_by_page(self): | ||
| self.graph.addVertex("person", {"name": "Alice", "age": 20}) | ||
| self.graph.addVertex("person", {"name": "Bob", "age": 23}) | ||
|
|
@@ -89,6 +106,16 @@ def test_remove_vertex_by_id(self): | |
| except NotFoundError as e: | ||
| self.assertTrue("Alice\\' does not exist" in str(e)) | ||
|
|
||
| def test_remove_vertex_by_number_id(self): | ||
| vertex = self.graph.addVertex("department", {"name": "DepartmentA", "headcount": 10, "floor": 1}) | ||
| self.graph.removeVertexById(vertex.id) | ||
| try: | ||
| self.graph.getVertexById(vertex.id) | ||
| except NotFoundError as e: | ||
| msg = "\\'{}\\' does not exist".format(vertex.id) | ||
| logger.info(f'test_msg: {msg}') | ||
|
|
||
| self.assertTrue(msg in str(e)) | ||
|
|
||
|
Comment on lines
+111
to
+118
|
||
| def test_add_edge(self): | ||
| vertex1 = self.graph.addVertex("person", {"name": "Alice", "age": 20}) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Please verify the actual server error text for a numeric vertex ID and update accordingly. Alternatively, drop the message assertion and rely only on |
||
| vertex2 = self.graph.addVertex("person", {"name": "Bob", "age": 23}) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Removing the trailing comma after
"rich"is unrelated to this bug fix and adds diff noise. TOML allows trailing commas; the original style is consistent with the rest of the list. Please revert this hunk.