Skip to content

fix: can't query vertex with number vertex id#329

Open
neoblackcap wants to merge 1 commit into
apache:mainfrom
neoblackcap:fix/number_type_vertex_id
Open

fix: can't query vertex with number vertex id#329
neoblackcap wants to merge 1 commit into
apache:mainfrom
neoblackcap:fix/number_type_vertex_id

Conversation

@neoblackcap
Copy link
Copy Markdown

  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

@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label May 11, 2026
@neoblackcap neoblackcap force-pushed the fix/number_type_vertex_id branch 2 times, most recently from 067b00d to bc2719d Compare May 11, 2026 10:47
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
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 department vertex 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.

Comment on lines +152 to +158
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}')
Comment on lines +111 to +118
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))

Copy link
Copy Markdown
Member

@imbajin imbajin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix direction is correct, but there is a critical regression and one incomplete fix:

  1. Critical regression (also +1'd Copilot #3224388877): the elif "{vertex_id}" in path substring check in huge_router.py also triggers on traverser.py routes (same_neighbors, jaccard_similarity — both contain vertex="{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 to json.dumps(vertex_id) (which also fixes the unused import json).

  2. Incomplete fix: graph.py:177 (getEdgeByPage) still hard-codes string quoting:

para = para + '&vertex_id="' + vertex_id + '"&direction=' + direction

This 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("&")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ No test added for 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)

Copy link
Copy Markdown
Member

@imbajin imbajin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ 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.

Suggested change
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})
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ The expected error pattern "\\'{}\\' 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"
]
Copy link
Copy Markdown
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python-client size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants