You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hugegraph.apache.org by "dosubot[bot] (via GitHub)" <gi...@apache.org> on 2025/05/05 09:09:22 UTC
Re: [I] [Bug] hugegraph-python documentation sample code error [incubator-hugegraph-ai]
dosubot[bot] commented on issue #218:
URL: https://github.com/apache/incubator-hugegraph-ai/issues/218#issuecomment-2850370815
<!-- Greeting -->
Hello @humblemat810! I'm here to help you solve bugs, answer questions, and guide you on becoming a contributor. While you're waiting for a human maintainer, feel free to ask me anything!
<!-- Answer -->
To address the issue with hardcoded vertex IDs in the hugegraph-python documentation, you can modify the sample code to use the vertex ID returned by the `addVertex` method. This approach avoids hardcoding and makes the code more dynamic and maintainable. Here's the corrected version of the code:
```python
from pyhugegraph.client import PyHugeClient
# Initialize the client
client = PyHugeClient("127.0.0.1", "8080", user="admin", pwd="admin", graph="hugegraph", graphspace="DEFAULT")
# Schema management
schema = client.schema()
schema.propertyKey("name").asText().ifNotExist().create()
schema.propertyKey("birthDate").asText().ifNotExist().create()
schema.vertexLabel("Person").properties("name", "birthDate").usePrimaryKeyId().primaryKeys("name").ifNotExist().create()
schema.vertexLabel("Movie").properties("name").usePrimaryKeyId().primaryKeys("name").ifNotExist().create()
schema.edgeLabel("ActedIn").sourceLabel("Person").targetLabel("Movie").ifNotExist().create()
# Graph operations
g = client.graph()
v1 = g.addVertex("Person", {"name": "Al Pacino", "birthDate": "1940-04-25"})
v2 = g.addVertex("Person", {"name": "Robert De Niro", "birthDate": "1943-08-17"})
v3 = g.addVertex("Movie", {"name": "The Godfather"})
v4 = g.addVertex("Movie", {"name": "The Godfather Part II"})
v5 = g.addVertex("Movie", {"name": "The Godfather Coda The Death of Michael Corleone"})
g.addEdge("ActedIn", v1.id, v3.id, {})
g.addEdge("ActedIn", v1.id, v4.id, {})
g.addEdge("ActedIn", v1.id, v5.id, {})
g.addEdge("ActedIn", v2.id, v4.id, {})
res = g.getVertexById(v1.id).label
print(res)
g.close()
```
This version uses the `id` attribute of the vertex objects returned by `addVertex` to add edges, eliminating the need for hardcoded IDs.
<!-- Dosu Comment Footer -->
*To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
---
<sup>Help Dosu learn! Give it feedback: [Great Response](https://app.dosu.dev/response-feedback/4e6a9972-1154-4e78-838d-480816efc1e2?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/4e6a9972-1154-4e78-838d-480816efc1e2?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/4e6a9972-1154-4e78-838d-480816efc1e2?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/4e6a9972-1154-4e78-838d-480816efc1e2?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/4e6a9972-1154-4e78-838d-480816efc1e2?feedback_type=hallucination) | [Bug Report](https://app.dosu.dev/response-feedback/4e6a9972-1154-4e78-838d-480816efc1e2?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/4e6a9972-1154-4e78-838d-480816efc1e2?feedback_type=other)</sup>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org