edgedb / edgedb

A graph-relational database with declarative schema, built-in migration system, and a next-generation query language
https://edgedb.com
Apache License 2.0
12.93k stars 396 forks source link

Enum migrations don't work #1943

Closed tailhook closed 3 years ago

tailhook commented 3 years ago

Even simple change like:

    scalar type Enum1 extending enum<Opt1, Opt2>;

->

    scalar type Enum1 extending enum<Opt1, Opt2, Opt3>;

Gives me (at create-migration):

Error: Server could not figure out migration with your answers. Please retry with different answers
Dhghomon commented 3 years ago

I've been meaning to file a report about a similar issue - can't even get simple enums to work at the moment and have simply blanked them out in the meantime while working on other stuff.

Dhghomon commented 3 years ago

When trying this:

START MIGRATION TO {
    module default {
scalar type Color extending enum<Red, Green, Blue>;
}

};

Here is the error I get:

ERROR: InternalServerError: 'TypeName' object has no attribute 'val'
  Hint: This is most likely a bug in EdgeDB. Please consider opening an issue ticket at https://github.com/edgedb/edgedb/issues/new?template=bug_report.md
  Server traceback:
      Traceback (most recent call last):
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-alpha6/lib/python3.8/site-packages/edb/server/procpool/worker.py", line 75, in worker
          res = await meth(*args)
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-alpha6/lib/python3.8/site-packages/edb/server/compiler/compiler.py", line 1795, in compile_eql_tokens
          return self._compile(ctx=ctx, tokens=eql_tokens)
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-alpha6/lib/python3.8/site-packages/edb/server/compiler/compiler.py", line 1429, in _compile
          comp: dbstate.BaseQuery = self._compile_dispatch_ql(ctx, stmt)
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-alpha6/lib/python3.8/site-packages/edb/server/compiler/compiler.py", line 1352, in _compile_dispatch_ql
          return self._compile_ql_migration(ctx, ql)
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-alpha6/lib/python3.8/site-packages/edb/server/compiler/compiler.py", line 789, in _compile_ql_migration
          target_schema = s_ddl.apply_sdl(
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-alpha6/lib/python3.8/site-packages/edb/schema/ddl.py", line 359, in apply_sdl
          cmd = cmd_from_ddl(
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-alpha6/lib/python3.8/site-packages/edb/schema/ddl.py", line 324, in cmd_from_ddl
          return sd.compile_ddl(schema, ddl, context=context)
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-alpha6/lib/python3.8/site-packages/edb/schema/delta.py", line 2938, in compile_ddl
          cmd = cmdcls._cmd_tree_from_ast(schema, astnode, context)
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-alpha6/lib/python3.8/site-packages/edb/schema/scalars.py", line 241, in _cmd_tree_from_ast
          cmd = super()._cmd_tree_from_ast(schema, astnode, context)
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-alpha6/lib/python3.8/site-packages/edb/schema/inheriting.py", line 649, in _cmd_tree_from_ast
          bases = cls._classbases_from_ast(schema, astnode, context)
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-alpha6/lib/python3.8/site-packages/edb/schema/inheriting.py", line 448, in _classbases_from_ast
          obj = utils.ast_to_object_shell(
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-alpha6/lib/python3.8/site-packages/edb/schema/utils.py", line 247, in ast_to_object_shell
          return ast_to_type_shell(
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-alpha6/lib/python3.8/site-packages/edb/schema/utils.py", line 128, in ast_to_type_shell
          elements=[
        File "/usr/lib/x86_64-linux-gnu/edgedb-server-1-alpha6/lib/python3.8/site-packages/edb/schema/utils.py", line 129, in <listcomp>
          st.val.value
      AttributeError: 'TypeName' object has no attribute 'val'
dmgolembiowski commented 3 years ago

I've worked out a general reproduction procedure for this error that is not dependent upon having an EdgeDB instance. A word of caution that it takes almost 20-30 minutes of stack trace crawling to reach it:

$ git clone <repo> # then build & install
$ python
>>> import pudb; pudb.set_trace()
>>> source = '''module default {
scalar type Color extending enum<Red, Green, Blue>;
}'''
...
>>> from edb.edgeql import parser
>>> syntax_lex = parser.parse_sdl(source);

and viola: AttributeError: 'TypeName' object has no attribute 'val'.

msullivan commented 3 years ago

The original issues are fixed. Enum changes in general are fairly restricted in DDL also, so there are a lot of other limitations that are easy to run into.

There's at least one follow-up filed, but I'm going to close this