Reputation: 1436
Using gremlinpython==3.7.0
per this Azure Doc, No matter what query I submit, the response is always "unhashable type: 'list'"
Unless the query results are empty, then it works fine.
Example 1 (query with no results):
query = f"g.V().has('label,'notareallabel')"
results = c.submit(query)
res = results.all().result()
returns []
, because there is no node with that label.
However if I run
query = f"g.V().has('label,'tank')"
results = c.submit(query)
res = results.all().result()
the results are "unhashable type: 'list'"
. I can confirm that this query would run by running it in the portal:
Obviously, the returned values is a list of two object. So it wouldn't surprise me that it is a list. But Gremlinpython doesn't parse it. Is there some way to make Gremlinpython expect a list? I've already tried all variants of values
valuemap
and other ways to format, but because the results I want are a list, it isn't parsing them.
Upvotes: 0
Views: 61
Reputation: 11
Do you have a simple example that could be copied and pasted? Your Python excerpts have (label is misspelled and there's a missing quote)
.has('lable,'tank')
while your screenshot of the Azure Portal's Data Explorer has
.has('label','tank')
Using the cosmicworks db and products graph example at the referenced MS page
https://learn.microsoft.com/en-us/azure/cosmos-db/gremlin/quickstart-python
% python --version
Python 3.9.16
% pip list | grep gremlinpython
gremlinpython 3.7.1
(I tried 3.7.0 as well with no problem)
% cat app.py
import os
from gremlin_python.driver import client, serializer
ACCOUNT_NAME = os.environ["COSMOS_GREMLIN_ID"]
ACCOUNT_KEY = os.environ["COSMOS_GREMLIN_KEY"]
client = client.Client(
url=f"wss://{ACCOUNT_NAME}.gremlin.cosmos.azure.com:443/",
traversal_source="g",
username="/dbs/cosmicworks/colls/products",
password=f"{ACCOUNT_KEY}",
message_serializer=serializer.GraphSONSerializersV2d0(),
)
query = f"g.V().has('label','product')"
results = client.submit(query)
res = results.all().result()
print(res)
% python app.py
[{'id': '68719518371', 'label': 'product', 'type': 'vertex', 'properties': {'name': [{'id': '2cd12649-4503-439c-95ef-0619494752f7', 'value': 'Kiama classic surfboard'}], 'price': [{'id': '0ae1acbe-f361-46a5-8c7c-2e17aadc6484', 'value': 285.55}], 'category': [{'id': '68719518371|category', 'value': 'surfboards'}]}}, {'id': '68719518403', 'label': 'product', 'type': 'vertex', 'properties': {'name': [{'id': 'ca16eba3-3c9b-4ee8-b734-5660d423f643', 'value': 'Montau Turtle Surfboard'}], 'price': [{'id': 'ce8af470-8142-40bf-b14e-29d06f6dd638', 'value': 600.0}], 'category': [{'id': '68719518403|category', 'value': 'surfboards'}]}}, {'id': '68719518409', 'label': 'product', 'type': 'vertex', 'properties': {'name': [{'id': '43d20d34-7271-4e2f-be57-a85e8fa85889', 'value': 'Bondi Twin Surfboard'}], 'price': [{'id': 'd8e48c98-5606-4d6e-a059-fb8fd34d3266', 'value': 585.5}], 'category': [{'id': '68719518409|category', 'value': 'surfboards'}]}}]
Upvotes: 1
Reputation: 1436
Not the best solution, but after much troubleshooting I found that it will work if you cast specific values, but not if you leave it open.
For example:
g.V().has('lable,'tank').valueMap()
will return "unhashable type: 'list'"
However:
g.V().has('lable,'tank').valueMap('name','display_name','description')
Will return values. I'm not sure why but it gives me a workaround. The bummer is that I have to know the properties of the node before I return them, which is limiting.
I think this might be more of an Azure issue than a gremlin issue. If you aren't working with Azure CosmosDB, you likely won't have this issue.
Upvotes: 0