fix: can't query vertex with number vertex id#329
Conversation
neoblackcap
commented
May 11, 2026
- make vertex api compactible with number type vertex id
- add test case for add/append/eliminate/remove vertex with number type vertex id
067b00d to
bc2719d
Compare
1. make vertex api compactible with number type vertex id 2. add test case for add/append/eliminate/remove vertex with number type vertex id
bc2719d to
e8b942b
Compare
There was a problem hiding this comment.
Pull request overview
This PR updates the HugeGraph Python client’s vertex APIs to support querying/operating on vertices whose IDs are numeric (not only string IDs), and adds regression tests around these vertex operations.
Changes:
- Adjusted vertex REST routes to remove always-on quoting around
{vertex_id}, and added router-side formatting logic intended to quote only string vertex IDs. - Added schema/test coverage for a new
departmentvertex label used to exercise numeric vertex-id behavior. - Tweaked
getVerticesById()query construction to JSON-quote ids (strings quoted, numbers not).
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| hugegraph-python-client/src/tests/client_utils.py | Adds new property keys and a department vertex label for numeric-id tests. |
| hugegraph-python-client/src/tests/api/test_graph.py | Adds new test cases covering append/eliminate/get/remove for numeric vertex IDs. |
| hugegraph-python-client/src/pyhugegraph/utils/huge_router.py | Adds special vertex_id formatting logic in the route formatter. |
| hugegraph-python-client/src/pyhugegraph/api/graph.py | Updates vertex endpoints to use unquoted {vertex_id} and adjusts getVerticesById() id quoting. |
| hugegraph-python-client/pyproject.toml | Minor dependency formatting adjustment. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| elif "{vertex_id}" in path: | ||
| # fix vertex_id format process | ||
| # only quote string type vertex_id | ||
| vertex_id = all_kwargs.pop("vertex_id") | ||
| if isinstance(vertex_id, str): | ||
| vertex_id = "\"" + vertex_id + "\"" | ||
| all_kwargs['vertex_id'] = vertex_id |
|
|
||
| import functools | ||
| import inspect | ||
| import json |
| schema.vertexLabel("book").useCustomizeStringId().properties("name", "price").nullableKeys( | ||
| "price" | ||
| ).ifNotExist().create() | ||
| schema.vertexLabel("department").properties("name", "headcount", "floor").nullableKeys( |
| self.graph.getVertexById(vertex.id) | ||
| except NotFoundError as e: | ||
| msg = "\\'{}\\' does not exist".format(vertex.id) | ||
| logger.info(f'test_msg: {msg}') |
| 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)) | ||
|
|
imbajin
left a comment
There was a problem hiding this comment.
Fix direction is correct, but there is a critical regression and one incomplete fix:
-
Critical regression (also +1'd Copilot #3224388877): the
elif "{vertex_id}" in pathsubstring check inhuge_router.pyalso triggers ontraverser.pyroutes (same_neighbors,jaccard_similarity— both containvertex="{vertex_id}"in their templates), causing string IDs to be double-quoted there (vertex=""person:marko""). Restrict the check to path-segment form, e.g.re.search(r'/\{vertex_id\}', path), or switch tojson.dumps(vertex_id)(which also fixes the unusedimport json). -
Incomplete fix:
graph.py:177(getEdgeByPage) still hard-codes string quoting:
para = para + '&vertex_id="' + vertex_id + '"&direction=' + directionThis produces a wrong URL when vertex_id is an integer — the same bug pattern fixed everywhere else in this PR. Please fix it here too, e.g.:
para = para + '&vertex_id=' + json.dumps(vertex_id) + '&direction=' + direction
|
|
||
| for vertex_id in quoted_vertex_ids: | ||
| path += f'ids={vertex_id}&' # pylint: disable=consider-using-join | ||
| path = path.rstrip("&") |
There was a problem hiding this comment.
getVerticesById with numeric IDs. This is the only changed code path in this method but none of the new test cases call it with an integer vertex ID. Please add a test (once the department schema ID strategy is fixed):
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)
imbajin
left a comment
There was a problem hiding this comment.
Fix direction is correct. Existing comments (#3224388877, imbajin, Copilot) cover the critical regression and several test issues. This review adds 4 new findings not yet raised.
Additional scope gap: traverser.py routes using other_id, source_id, target_id (e.g. same_neighbors, jaccard_similarity, shortest_path) have the same quoting pattern as the fixed graph.py routes, but are not addressed by this PR. Numeric values for those parameters will still fail. Suggest either scoping the PR title/description to vertex_id only, or extending the fix to cover these.
| for vertex_id in vertex_ids: | ||
| path += f'ids="{vertex_id}"&' # pylint: disable=consider-using-join | ||
| quoted_vertex_ids = map(json.dumps, vertex_ids) | ||
|
|
There was a problem hiding this comment.
json.dumps without ensure_ascii=False will Unicode-escape non-ASCII vertex IDs — json.dumps("\u4eba\u540d") produces '"\\u4eba\\u540d"' instead of '"\u4eba\u540d"', causing HugeGraph lookups to fail for any non-ASCII string vertex ID.
| quoted_vertex_ids = (json.dumps(vid, ensure_ascii=False) for vid in vertex_ids) |
| self.assertTrue(msg in str(e)) | ||
|
|
||
| def test_add_edge(self): | ||
| vertex1 = self.graph.addVertex("person", {"name": "Alice", "age": 20}) |
There was a problem hiding this comment.
"\\'{}\\' does not exist" was copied from the string-ID test where IDs have the form label:name. For AUTOMATIC numeric IDs (e.g. 42), HugeGraph's server error format may differ — numeric IDs may not be wrapped in single-quotes in the error message.
Please verify the actual server error text for a numeric vertex ID and update accordingly. Alternatively, drop the message assertion and rely only on assertRaises(NotFoundError) (see also the silent-pass issue already flagged in this block).
| "urllib3", | ||
| "rich", | ||
| "rich" | ||
| ] |
There was a problem hiding this comment.
🧹 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.