vaticle / typedb-driver-python

TypeDB Driver for Python
https://typedb.com
Apache License 2.0
67 stars 25 forks source link

Python client API: .transaction.execute() method fails #128

Closed JonThom closed 2 years ago

JonThom commented 3 years ago

Description

In Python client API, .transaction.execute() produces the error AttributeError: 'Transaction' object has no attribute 'execute'

Environment

  1. OS (where Grakn server runs): Mac OS Mojave 10.14.6
  2. Grakn version (and platform): Grakn Core 1.8.1
  3. Grakn client-python version: client-python 1.8.1
  4. Python version: 3.7.5

Reproducible Steps

in terminal:

grakn server start
grakn console -k socialnetwork --f schema.gql
grakn console -k socialnetwork --f data.gql

in Python:

client = GraknClient(uri="localhost:48555")
from grakn.client import GraknClient
with client.session(keyspace="socialnetwork") as session:
    with session.transaction().read() as read_transaction:   
         answer_iterator = read_transaction.execute(query="match $x sub person; get; limit 1;")

Expected Output

Expected answer_iterator to be an iterator yielding the 'person' type

Actual Output

AttributeError: 'Transaction' object has no attribute 'execute'

Additional info

vmax commented 3 years ago

@JonThom thank you for reporting it! The correct way to make a query would be:

client = GraknClient(uri="localhost:48555")
from grakn.client import GraknClient
with client.session(keyspace="socialnetwork") as session:
    with session.transaction().read() as read_transaction:   
         answer_iterator = read_transaction.query("match $x sub person; get; limit 1;")

I've raised the issue on docs being invalid in this case: graknlabs/docs#334

JonThom commented 3 years ago

@vmax possibly related, re: local and remote concept API

after upgrading Grakn and the Python grakn-client (v 1.8.x), I prepended the .as_remote(tx) method to some non-local concept method calls, e.g.:

dict_roleplayers = rel.as_remote(read_transaction).role_players_map()

However, for most concept API methods, this led to an exception:

File "/Applications/anaconda3/envs/grakn-new/lib/python3.7/site-packages/grakn/service/Session/Concept/RemoteConcept.py", line 525, in role_players_map

pairs = list(map(to_pair, self._tx_service.run_concept_iter_method(self.id, role_players_map_req)))

AttributeError: 'Transaction' object has no attribute 'run_concept_iter_method'

In fact, in my code, the .as_remote() method only seems to work for the .playing(), .sup() and .roles() methods (all type methods) . All other concept methods in my code have to be executed on local objects.

I imagine you might have an idea of what is going wrong and could log the issue with more relevant background information. Otherwise I'm happy to log it.

flyingsilverfin commented 3 years ago

@adammitchelldev this might be something for you to look into after your refactor to support async?

alexjpwalker commented 3 years ago

We have just released https://github.com/graknlabs/client-python/releases/tag/2.0.0-alpha - it is very likely that the issue is resolved. The code architecture has been overhauled.

alexjpwalker commented 2 years ago

As execute no longer exists in TypeDB Clients, this issue has gone away.