Error running unhas: RelationshipReified cannot be cast to Relationship


#1

I get the following error trying to run “unhas” in the python client

grakn.exception.GraknError.GraknError: Server/network error: <_Rendezvous of RPC that terminated with:
	status = StatusCode.UNKNOWN
	details = "ai.grakn.kb.internal.concept.RelationshipReified cannot be cast to ai.grakn.concept.Relationship. Please check server logs for the stack trace."
	debug_error_string = "{"created":"@1543441514.659025000","description":"Error received from peer","file":"src/core/lib/surface/call.cc","file_line":1017,"grpc_message":"ai.grakn.kb.internal.concept.RelationshipReified cannot be cast to ai.grakn.concept.Relationship. Please check server logs for the stack trace.","grpc_status":2}"

Here is a program that reproduces the error against an empty keyspace:

import grakn

GRAKN_CLIENT = grakn.Grakn(uri="localhost:48555")
GRAKN_SESSION = GRAKN_CLIENT.session(keyspace="demo2")

with GRAKN_SESSION.transaction(grakn.TxType.WRITE) as tx:
    tx.query('''
        define
        group sub entity plays member_of;
        person sub entity plays member;
        membership sub relationship relates member relates member_of has name;
        name sub attribute datatype string;
    ''')

    tx.query('''
        insert
        $p isa person;
        $g isa group;
        (member: $p, member_of: $g) isa membership has name "founder";
    ''')
    
    membership = tx.query('match $x isa membership; get;').collect_concepts()[0]
    for attr in membership.attributes():
        membership.unhas(attr)
    tx.commit()

I am running grakn 1.4.2, python client 1.4.2

I don’t know if I’m using unhas or attributes wrong, or if this is a grakn bug

Edit 2018-11-29: replaced membership.keys() with membership.attributes()


#2

What I’m trying to do in my real dataset is “update” the “field”, as if the membership relationship is a record in a table. has() will add an attribute to the thing; I’m instead trying to replace the attribute with a new value


Update exiting data
#3

There’s a subtle difference between attributes and attributes that are keys: attributes attached to things as keys are checked to be unique for the given type and declared in the schema with the key keyword:

membership sub relationship, relates member, relates member_of, key name; # unique attribute for `membership`

vs

membership sub relationship, relates member, relates member_of, has name;  # just an attribute

the .keys() functionality returns any keys attached to the Thing. Since you’ve not defined any keys, try to get the attribute with .attributes(). If you intend to use keys, I don’t think we currently support deleting keys off of Things.

Hope that helps!


#4

I was not aware keys existed. They aren’t mentioned at https://dev.grakn.ai/docs/building-schema/defining-schema . Regardless, I still get the same error if I replace

for attr in membership.keys():

with

for attr in membership.attributes():

#5

@soroush is currently hard at work at upating documentation for 1.5, which we’re all looking forward to seeing!

Regarding the unhas problem, it appears to be a bug when trying to remove an attribute from a relationship; the operation should be fine on entities (& I imagine attributes on attributes too).

@kasper I can confirm the error is the one given in the first post - RelationshipReified vs Relationship casting problems. I’ll make an issue for it.

Thanks for finding the bug and helping us improve Grakn!