3

I'm using Grakn 1.8.1, python 3.6.8, grakn-client 1.8.1 and grpcio 1.24.1.

I defined a simple schema (schema.gql) just to perform a test:

define

nome sub attribute,
    value string;

cpf_srfb sub attribute,
    value string;

id_srfb sub attribute,
    value string;

hops_de_contraparte sub attribute,
    value string;

pessoa_fisica sub entity,
    has nome,
    has cpf_srfb,
    has id_srfb,
    has hops_de_contraparte;

This scheme was correctly loaded using the grakn console and the keyspace was called 'srfb'.

After that, I created a data file (data.sql) containing only one instance:

insert $pf isa pessoa_fisica, has nome "GUSTAVO RIBEIRO SOARES PINTO", has cpf_srfb "***106887**", has id_srfb "***106887**GUSTAVO RIBEIRO SOARES PINTO", has hops_de_contraparte "5";

Again, the data load worked perfectly using the grakn-console.

The problem occurs when I load the schema via console and then I try to load the data via python api.

My python script is just:

from grakn.client import GraknClient

uri = "localhost:48555"
keyspace = 'srfb'
filepath = 'C:\grakn\grakn_181\data.gql'

with open(filepath, mode='r') as file:
    insert_query = file.read()

with GraknClient(uri) as client:
    with client.session(keyspace) as session:
        with session.transaction().write() as transaction:
            transaction.query(insert_query)
            transaction.commit()

At that moment, an error occurs that I cannot correct:

Traceback (most recent call last):
  File "C:\Users\jorge\AppData\Local\Programs\Python\Python36\lib\site-packages\grakn\service\Session\util\Communicator.py", line 166, in _block_for_next
    response = next(self._response_iterator)
  File "C:\Users\jorge\AppData\Local\Programs\Python\Python36\lib\site-packages\grpc\_channel.py", line 388, in __next__
    return self._next()
  File "C:\Users\jorge\AppData\Local\Programs\Python\Python36\lib\site-packages\grpc\_channel.py", line 382, in _next
    raise self
grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated with:
        status = StatusCode.UNKNOWN
        details = "grakn.core.kb.graql.exception.GraqlSemanticException: hops_de_contraparte doesn't have an 'isa', a 'sub' or an 'id'. Please check server logs for the stack trace."
        debug_error_string = "{"created":"@1603911191.241000000","description":"Error received from peer ipv6:[::1]:48555","file":"src/core/lib/surface/call.cc","file_line":1055,"grpc_message":"grakn.core.kb.graql.exception.GraqlSemanticException: hops_de_contraparte doesn't have an 'isa', a 'sub' or an 'id'. Please check server logs for the stack trace.","grpc_status":2}"
>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "teste.py", line 17, in <module>
    transaction.commit()
  File "C:\Users\jorge\AppData\Local\Programs\Python\Python36\lib\site-packages\grakn\client.py", line 160, in commit
    self._tx_service.commit()
  File "C:\Users\jorge\AppData\Local\Programs\Python\Python36\lib\site-packages\grakn\service\Session\TransactionService.py", line 54, in commit
    self._communicator.single_request(request)
  File "C:\Users\jorge\AppData\Local\Programs\Python\Python36\lib\site-packages\grakn\service\Session\util\Communicator.py", line 192, in single_request
    return SingleResolver(self, request).get()
  File "C:\Users\jorge\AppData\Local\Programs\Python\Python36\lib\site-packages\grakn\service\Session\util\Communicator.py", line 70, in get
    response = self._communicator._block_for_next(self)
  File "C:\Users\jorge\AppData\Local\Programs\Python\Python36\lib\site-packages\grakn\service\Session\util\Communicator.py", line 184, in _block_for_next
    raise self._error
grakn.exception.GraknError.GraknError: Server/network error: <_Rendezvous of RPC that terminated with:
        status = StatusCode.UNKNOWN
        details = "grakn.core.kb.graql.exception.GraqlSemanticException: hops_de_contraparte doesn't have an 'isa', a 'sub' or an 'id'. Please check server logs for the stack trace."
        debug_error_string = "{"created":"@1603911191.241000000","description":"Error received from peer ipv6:[::1]:48555","file":"src/core/lib/surface/call.cc","file_line":1055,"grpc_message":"grakn.core.kb.graql.exception.GraqlSemanticException: hops_de_contraparte doesn't have an 'isa', a 'sub' or an 'id'. Please check server logs for the stack trace.","grpc_status":2}"
>

 generated from request: iter_req {
  options {
  }
  query_iter_req {
    query: "insert $pf isa pessoa_fisica, has nome \"GUSTAVO RIBEIRO SOARES PINTO\", has cpf_srfb \"***106887**\", has id_srfb \"***106887**GUSTAVO RIBEIRO SOARES PINTO\", has hops_de_contraparte \"5\";"
    options {
    }
  }
}


The grakn log presents the following record:

2020-10-28 15:15:45,615 [grpc-request-handler-3] ERROR g.c.s.r.SessionService$TransactionListener - Runtime Exception in RPC TransactionListener: 
java.util.concurrent.ExecutionException: grakn.core.kb.graql.exception.GraqlSemanticException: hops_de_contraparte doesn't have an 'isa', a 'sub' or an 'id'
    at java.util.concurrent.FutureTask.report(Unknown Source)
    at java.util.concurrent.FutureTask.get(Unknown Source)
    at grakn.core.server.rpc.SessionService$TransactionListener.process(SessionService.java:319)
    at grakn.core.server.rpc.SessionService$TransactionListener.onNext(SessionService.java:196)
    at grakn.core.server.rpc.SessionService$TransactionListener.onNext(SessionService.java:156)
    at io.grpc.stub.ServerCalls$StreamingServerCallHandler$StreamingServerCallListener.onMessage(ServerCalls.java:251)
    at io.grpc.internal.ServerCallImpl$ServerStreamListenerImpl.messagesAvailableInternal(ServerCallImpl.java:309)
    at io.grpc.internal.ServerCallImpl$ServerStreamListenerImpl.messagesAvailable(ServerCallImpl.java:292)
    at io.grpc.internal.ServerImpl$JumpToApplicationThreadServerStreamListener$1MessagesAvailable.runInContext(ServerImpl.java:779)
    at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:37)
    at io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:123)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: grakn.core.kb.graql.exception.GraqlSemanticException: hops_de_contraparte doesn't have an 'isa', a 'sub' or an 'id'

Initially I thought there was a problem with the declaration of the attributes, but it is not the case, because the same insert works perfectly via console.

What could I do to be able to use the python api? Does anyone have an idea of ​​what I might be doing wrong?

Jorge
  • 167
  • 8

3 Answers3

0

Does it work if you don't read from the file, and just set insert query directly?

insert_query ="insert $pf isa pessoa_fisica, has nome \"GUSTAVO RIBEIRO SOARES PINTO\", has cpf_srfb \"***106887**\", has id_srfb \"***106887**GUSTAVO RIBEIRO SOARES PINTO\", has hops_de_contraparte \"5\";"
James Fletcher
  • 920
  • 11
  • 13
Banjo Obayomi
  • 1,636
  • 15
  • 17
0

As you already know from the fact that everything loaded in via the console correctly, you aren't doing anything visibly wrong!

This message:

hops_de_contraparte doesn't have an 'isa', a 'sub' or an 'id'

is a sure sign that the keyspace you are accessing from the python client doesn't have hops_de_contraparte defined as a type. You could be accessing a different keyspace from the console than you are from the client. So, please double-check that when loading the schema using the console you are using the -k argument to give the keyspace, like: .\grakn console -k srfb -f 'C:\grakn\grakn_181\schema.gql so that it matches with the keyspace you use for the client.

Failing that, try changing the query you make to remove hops_de_contraparte to see if it's that type in particular that isn't defined. Do as Banjo suggests and try passing the query from a Python string first.

James Fletcher
  • 920
  • 11
  • 13
  • The problem is not with hops_de_contraparte. I removed this attribute from the query and the log was exactly the same, but with the last remaining attribute (id_srfb). This happened with all attributes. Although the log always presents the problem with the latter attribute, it appears that the keyspace is not accessed at all. – Jorge Oct 29 '20 at 12:05
0

I cleaned up the keyspace, restarted all the process and the script worked correctly. I don't know what the problem was, but it was solved. Thanks for your help James and Banjo.

Jorge
  • 167
  • 8