typedb / typedb

TypeDB: the power of programming, in your database
https://typedb.com
Mozilla Public License 2.0
3.8k stars 337 forks source link

Entity and Role naming bug. #5187

Closed samlaws closed 5 years ago

samlaws commented 5 years ago

Description

When changing the name of a role to one that has previously belonged to an entity results in a grakn client exception.

Environment

  1. OS (where Grakn server runs): Windows 10
  2. Grakn version (and platform): Grakn Core 1.5.1
  3. Grakn client: console
  4. Other environment details: -

Reproducible Steps

Steps to create the smallest reproducible scenario:

  1. Run the gql file into a keyspace 'ownership_keyspace':
    
    define

person sub entity, has name, plays owner;

owned-object sub entity, has name, plays owned-object-test;

ownership sub relation, relates owner, relates owned-object-test;

name sub attribute, datatype string;

2. Then if you decide to change the names of the roles/entities and run this gql file into the same keyspace:

define

person sub entity, has name, plays owner;

object sub entity, has name, plays owned-object;

ownership sub relation, relates owner, relates owned-object;

name sub attribute, datatype string;

## Expected Output

Schema should be updated with new names.

## Actual Output

Failed to load file error:

Failed to load file: ownership_schema.gql Cause: grakn.client.exception.GraknClientException UNKNOWN: The concept [Base Type [ENTITY_TYPE] - Id [V4288] - Label [owned-object] ] is not of type [interface grakn.core.concept.type.Role]. Please check server logs for the stack trace.


## Additional information

Not a huge issue as the 2nd file works fine in a new keyspace.

[Attached log file: grakn.txt](https://github.com/graknlabs/grakn/files/3177384/grakn.txt)
kasper-piskorski commented 5 years ago

This is by design the expected behaviour, otherwise potential errors in the schema could result in silent schema overwrites.

Instead you should first undefine your entity type:

undefine owned-object sub entity;

and then update the relation/entity definition:

define
ownership sub relation,
    relates owner,
    relates owned-object;

object sub entity,
    has name,
    plays owned-object;

Hope that helps.

samlaws commented 5 years ago

OK thanks for the response that makes a lot of sense, I'll go ahead and close the issue now.

Cheers