Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two computed properties with same name and no property keyword cause InternalServerError #5725

Closed
Dhghomon opened this issue Jun 30, 2023 · 1 comment · Fixed by #5785
Closed

Comments

@Dhghomon
Copy link
Contributor

Dhghomon commented Jun 30, 2023

  • EdgeDB Version: 3.0+e7d38e9
  • EdgeDB CLI Version: 3.1.3+9fdca62
  • OS Version: Windows 11

I'm rewriting part of Chapter 18 in Easy EdgeDB on currencies at the moment and came across a bug that happens when you mistakenly give two computed properties the same name. Here's a simplified example of what I was putting together:

Steps to Reproduce:

  1. Create a schema that has two computables with the same name (i.e. a user typo) and no property keyword:
module default {

  type SimpleNumbers {
    required num1: int64;
    read_num1 := .num1;
    read_num1 := .num1;
  }
}
  1. edgedb migration create to get this error:
edgedb error: InternalServerError: <QualName default::SimpleNumbers@read_num1>
  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 "/home/edgedb/.local/share/edgedb/portable/3.0/lib/python3.11/site-packages/edb/server/compiler_pool/worker.py", line 161, in compile
          units, cstate = COMPILER.compile(
                          ^^^^^^^^^^^^^^^^^
        File "/home/edgedb/.local/share/edgedb/portable/3.0/lib/python3.11/site-packages/edb/server/compiler/compiler.py", line 755, in compile
          unit_group = compile(ctx=ctx, source=source)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/home/edgedb/.local/share/edgedb/portable/3.0/lib/python3.11/site-packages/edb/server/compiler/compiler.py", line 1944, in compile
          return _try_compile(ctx=ctx, source=source)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/home/edgedb/.local/share/edgedb/portable/3.0/lib/python3.11/site-packages/edb/server/compiler/compiler.py", line 2012, in _try_compile
          comp, capabilities = _compile_dispatch_ql(
                               ^^^^^^^^^^^^^^^^^^^^^
        File "/home/edgedb/.local/share/edgedb/portable/3.0/lib/python3.11/site-packages/edb/server/compiler/compiler.py", line 1851, in _compile_dispatch_ql
          query = ddl.compile_dispatch_ql_migration(
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/home/edgedb/.local/share/edgedb/portable/3.0/lib/python3.11/site-packages/edb/server/compiler/ddl.py", line 382, in compile_dispatch_ql_migration
          return _start_migration(ctx, ql, in_script)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/home/edgedb/.local/share/edgedb/portable/3.0/lib/python3.11/site-packages/edb/server/compiler/ddl.py", line 463, in _start_migration
          target_schema = s_ddl.apply_sdl(
                          ^^^^^^^^^^^^^^^^
        File "/home/edgedb/.local/share/edgedb/portable/3.0/lib/python3.11/site-packages/edb/schema/ddl.py", line 520, in apply_sdl
          ddl_stmts = s_decl.sdl_to_ddl(target_schema, documents)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/home/edgedb/.local/share/edgedb/portable/3.0/lib/python3.11/site-packages/edb/edgeql/declarative.py", line 453, in sdl_to_ddl
          trace_dependencies(decl_ast, ctx=tracectx)
        File "/home/edgedb/.local/share/edgedb/portable/3.0/lib/python3.11/functools.py", line 909, in wrapper
          return dispatch(args[0].__class__)(*args, **kw)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/home/edgedb/.local/share/edgedb/portable/3.0/lib/python3.11/site-packages/edb/edgeql/declarative.py", line 1055, in trace_default
          _register_item(node, ctx=ctx)
        File "/home/edgedb/.local/share/edgedb/portable/3.0/lib/python3.11/site-packages/edb/edgeql/declarative.py", line 1189, in _register_item
          trace_dependencies(cmd, ctx=ctx)
        File "/home/edgedb/.local/share/edgedb/portable/3.0/lib/python3.11/functools.py", line 909, in wrapper
          return dispatch(args[0].__class__)(*args, **kw)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/home/edgedb/.local/share/edgedb/portable/3.0/lib/python3.11/site-packages/edb/edgeql/declarative.py", line 822, in trace_SetField
          _register_item(node, deps=deps, hard_dep_exprs=exprs, ctx=ctx)
        File "/home/edgedb/.local/share/edgedb/portable/3.0/lib/python3.11/site-packages/edb/edgeql/declarative.py", line 1080, in _register_item
          vn = get_verbosename_from_fqname(fq_name, ctx)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/home/edgedb/.local/share/edgedb/portable/3.0/lib/python3.11/site-packages/edb/edgeql/declarative.py", line 235, in get_verbosename_from_fqname
          traceobj = ctx.objects[fq_name]
                     ~~~~~~~~~~~^^^^^^^^^
      KeyError: <QualName default::SimpleNumbers@read_num1>

If at least one of the computed properties has the keyword property then the compiler error is a normal one:

error: property 'read_num1' of object type 'default::SimpleNumbers' was already declared
  ┌─ c:\rust\anything\dbschema\default.esdl:6:5
  │
6 │     property read_num1 := .num1;
  │     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error

edgedb error: cannot proceed until .esdl files are fixed
@msullivan
Copy link
Member

Yeah, this one is kind of funny: read_num1 := .num1; doesn't declare a computed property, but tries to set a field named read_num1. (Fields are things like default and readonly).

This gets detected as declaring the same field twice, but the code path for formatting the field name doesn't work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants