typedb icon indicating copy to clipboard operation
typedb copied to clipboard

Defining player of inherited role actually results in playing the supertype relation's role

Open JonThom opened this issue 3 years ago • 4 comments

Description

As we know, when subtyping a relation, any roles that are not explicitly subtyped are implicitly inherited by the subtype:

define super_rel sub relation, relates super_rel_role, relates super_rel_role_2;
define sub_rel sub super_rel;
# sub_rel automatically inherits super_rel roles. They keep super_rel as their scope

So far so good.

But now, undefine sub_rel relates super_rel_role; should lead to an error since sub_rel has inherited super_rel_role.

However, what happens is equivalent to undefine super_rel relates super_rel_role, i.e. the role is undefined.

Environment

  1. OS (where TypeDB server runs): Mac OS 12.2.1
  2. TypeDB version (and platform): TypeDB 2.6.3
  3. TypeDB client: client-python, console

Reproducible Steps

See above.

Expected Output

Exception

Actual Output

The super_rel_role is undefined.

JonThom avatar Apr 06 '22 08:04 JonThom

Very interesting! Does look like erroneous behaviour.

jmsfltchr avatar Apr 08 '22 10:04 jmsfltchr

Edited example slightly: adds super_rel_role_2 to avoid raising unrelated exception due to undefining last role

JonThom avatar Apr 08 '22 10:04 JonThom

Something very similar was spotted in the IAM schema. We declare the following:

action sub entity, abstract,
    plays set-membership:member;

But in the TypeDB Studio, it says that action plays membership:member. The role member, as you might have guessed is inherited from the membership relation.

set-membership sub membership,
    relates set as parent;

membership sub relation,
    relates parent,
    relates member;

izmalk avatar Apr 19 '23 11:04 izmalk

@flyingsilverfin With the following schema:

define
person sub entity;
membership sub relation;
membership relates member;
club-membership sub membership;
person plays club-membership:member;

person instances can play the member role in both membership and club-membership instances. Querying:

match
$x plays $y;

returns:

{
    $x type person sub entity;
    $y type membership:member sub relation:role;
}

If I define person plays club-membership:member; then person should only be able to play member in instances of club-membership.

james-whiteside avatar Sep 04 '23 10:09 james-whiteside