vaticle / typedb

TypeDB: the polymorphic database powered by types
https://typedb.com
Mozilla Public License 2.0
3.72k stars 337 forks source link

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

Open JonThom opened 2 years ago

JonThom commented 2 years ago

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.

jmsfltchr commented 2 years ago

Very interesting! Does look like erroneous behaviour.

JonThom commented 2 years ago

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

izmalk commented 1 year ago

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;
james-whiteside commented 10 months ago

@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.