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

InvalidReferenceError when using #[edgedb(json)] container level with <json> type casting #316

Closed
MrFoxPro opened this issue Apr 17, 2024 · 3 comments

Comments

@MrFoxPro
Copy link
Contributor

MrFoxPro commented Apr 17, 2024

According to this:
https://github.com/edgedb/edgedb-rust/blob/master/edgedb-derive/src/lib.rs#L59-L74
I wrote code:

type OtpPhoneRequest {
   required phone: str;
   required otp: int32;
   required sent_at: datetime;
   confirmed_at: datetime;
}
#[derive(Clone, Debug, Serialize, Deserialize, Queryable)]
#[edgedb(json)]
pub struct OtpPhoneRequest {
   pub id: String,
   pub phone: String,
}

edb.query::<OtpPhoneRequest, _>(
    "select <json>OtpPhoneRequest { id, phone }",
    &()
 )
 .await?;

An error happened:

Error
Message: InvalidReferenceError: invalid property reference on a primitive type expression (on line 1, column 51)
Span: 50-53, line 1, column 51
Server traceback:
    Traceback (most recent call last):
      File "/nix/store/inwpvs9il30f1sd9arjkxg81acnw87yy-edgedb-server/lib/python3.11/site-packages/edb/server/compiler_pool/worker.py", line 178, in compile
        units, cstate = COMPILER.compile(
                        ^^^^^^^^^^^^^^^^^
      File "/nix/store/inwpvs9il30f1sd9arjkxg81acnw87yy-edgedb-server/lib/python3.11/site-packages/edb/server/compiler/compiler.py", line 885, in compile
        unit_group = compile(ctx=ctx, source=source)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/nix/store/inwpvs9il30f1sd9arjkxg81acnw87yy-edgedb-server/lib/python3.11/site-packages/edb/server/compiler/compiler.py", line 2309, in compile
        return _try_compile(ctx=ctx, source=source)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/nix/store/inwpvs9il30f1sd9arjkxg81acnw87yy-edgedb-server/lib/python3.11/site-packages/edb/server/compiler/compiler.py", line 2370, in _try_compile
        comp, capabilities = _compile_dispatch_ql(
                             ^^^^^^^^^^^^^^^^^^^^^
      File "/nix/store/inwpvs9il30f1sd9arjkxg81acnw87yy-edgedb-server/lib/python3.11/site-packages/edb/server/compiler/compiler.py", line 2283, in _compile_dispatch_ql
        query = _compile_ql_query(ctx, ql, script_info=script_info)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/nix/store/inwpvs9il30f1sd9arjkxg81acnw87yy-edgedb-server/lib/python3.11/site-packages/edb/server/compiler/compiler.py", line 1707, in _compile_ql_query
        ir = qlcompiler.compile_ast_to_ir(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/nix/store/inwpvs9il30f1sd9arjkxg81acnw87yy-edgedb-server/lib/python3.11/site-packages/edb/edgeql/compiler/__init__.py", line 179, in wrapper
        return func(*args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^
      File "/nix/store/inwpvs9il30f1sd9arjkxg81acnw87yy-edgedb-server/lib/python3.11/site-packages/edb/edgeql/compiler/__init__.py", line 270, in compile_ast_to_ir
        ir_set = dispatch_mod.compile(tree, ctx=ctx)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/nix/store/inwpvs9il30f1sd9arjkxg81acnw87yy-edgedb-server/lib/python3.11/functools.py", line 909, in wrapper
        return dispatch(args[0].__class__)(*args, **kw)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/nix/store/inwpvs9il30f1sd9arjkxg81acnw87yy-edgedb-server/lib/python3.11/site-packages/edb/edgeql/compiler/stmt.py", line 137, in compile_SelectQuery
        stmt.where = clauses.compile_where_clause(expr.where, ctx=sctx)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/nix/store/inwpvs9il30f1sd9arjkxg81acnw87yy-edgedb-server/lib/python3.11/site-packages/edb/edgeql/compiler/clauses.py", line 55, in compile_where_clause
        ir_expr = dispatch.compile(where, ctx=subctx)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/nix/store/inwpvs9il30f1sd9arjkxg81acnw87yy-edgedb-server/lib/python3.11/functools.py", line 909, in wrapper
        return dispatch(args[0].__class__)(*args, **kw)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/nix/store/inwpvs9il30f1sd9arjkxg81acnw87yy-edgedb-server/lib/python3.11/site-packages/edb/edgeql/compiler/expr.py", line 135, in compile_BinOp
        op_node = func.compile_operator(
                  ^^^^^^^^^^^^^^^^^^^^^^
      File "/nix/store/inwpvs9il30f1sd9arjkxg81acnw87yy-edgedb-server/lib/python3.11/site-packages/edb/edgeql/compiler/func.py", line 363, in compile_operator
        arg_ir = polyres.compile_arg(
                 ^^^^^^^^^^^^^^^^^^^^
      File "/nix/store/inwpvs9il30f1sd9arjkxg81acnw87yy-edgedb-server/lib/python3.11/site-packages/edb/edgeql/compiler/polyres.py", line 607, in compile_arg
        arg_ir = dispatch.compile(arg_ql, ctx=argctx)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/nix/store/inwpvs9il30f1sd9arjkxg81acnw87yy-edgedb-server/lib/python3.11/functools.py", line 909, in wrapper
        return dispatch(args[0].__class__)(*args, **kw)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/nix/store/inwpvs9il30f1sd9arjkxg81acnw87yy-edgedb-server/lib/python3.11/site-packages/edb/edgeql/compiler/expr.py", line 77, in compile_Path
        return stmt.maybe_add_view(setgen.compile_path(expr, ctx=ctx), ctx=ctx)
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/nix/store/inwpvs9il30f1sd9arjkxg81acnw87yy-edgedb-server/lib/python3.11/site-packages/edb/edgeql/compiler/setgen.py", line 477, in compile_path
        path_tip = ptr_step_set(
                   ^^^^^^^^^^^^^
      File "/nix/store/inwpvs9il30f1sd9arjkxg81acnw87yy-edgedb-server/lib/python3.11/site-packages/edb/edgeql/compiler/setgen.py", line 642, in ptr_step_set
        ptrcls, path_id_ptrcls = resolve_ptr_with_intersections(
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/nix/store/inwpvs9il30f1sd9arjkxg81acnw87yy-edgedb-server/lib/python3.11/site-packages/edb/edgeql/compiler/setgen.py", line 718, in resolve_ptr_with_intersections
        raise errors.InvalidReferenceError(msg, context=source_context)
    edb.errors.InvalidReferenceError: invalid property reference on a primitive type expression
Other attributes:
  0xfff9: b"50"
  0xfffa: b"53"
  0xfff7: b"54"
  0xfff6: b"1"
  0xfff8: b"53"
  0xfff5: b"50"
  0x0101: b"Traceback (most recent call last):\n  File \"/nix/store/inwpvs9il30f1sd9arjkxg81acnw87yy-edgedb-server/lib/python3.11/site-packages/edb/server/compiler_pool/worker.py\", line 178, in compile\n    units, cstate = COMPILER.compile(\n                    ^^^^^^^^^^^^^^^^^\n  File \"/nix/store/inwpvs9il30f1sd9arjkxg81acnw87yy-edgedb-server/lib/python3.11/site-packages/edb/server/compiler/compiler.py\", line 885, in compile\n    unit_group = compile(ctx=ctx, source=source)\n                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/nix/store/inwpvs9il30f1sd9arjkxg81acnw87yy-edgedb-server/lib/python3.11/site-packages/edb/server/compiler/compiler.py\", line 2309, in compile\n    return _try_compile(ctx=ctx, source=source)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/nix/store/inwpvs9il30f1sd9arjkxg81acnw87yy-edgedb-server/lib/python3.11/site-packages/edb/server/compiler/compiler.py\", line 2370, in _try_compile\n    comp, capabilities = _compile_dispatch_ql(\n                         ^^^^^^^^^^^^^^^^^^^^^\n  File \"/nix/store/inwpvs9il30f1sd9arjkxg81acnw87yy-edgedb-server/lib/python3.11/site-packages/edb/server/compiler/compiler.py\", line 2283, in _compile_dispatch_ql\n    query = _compile_ql_query(ctx, ql, script_info=script_info)\n            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/nix/store/inwpvs9il30f1sd9arjkxg81acnw87yy-edgedb-server/lib/python3.11/site-packages/edb/server/compiler/compiler.py\", line 1707, in _compile_ql_query\n    ir = qlcompiler.compile_ast_to_ir(\n         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/nix/store/inwpvs9il30f1sd9arjkxg81acnw87yy-edgedb-server/lib/python3.11/site-packages/edb/edgeql/compiler/__init__.py\", line 179, in wrapper\n    return func(*args, **kwargs)\n           ^^^^^^^^^^^^^^^^^^^^^\n  File \"/nix/store/inwpvs9il30f1sd9arjkxg81acnw87yy-edgedb-server/lib/python3.11/site-packages/edb/edgeql/compiler/__init__.py\", line 270, in compile_ast_to_ir\n    ir_set = dispatch_mod.compile(tree, ctx=ctx)\n             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/nix/store/inwpvs9il30f1sd9arjkxg81acnw87yy-edgedb-server/lib/python3.11/functools.py\", line 909, in wrapper\n    return dispatch(args[0].__class__)(*args, **kw)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/nix/store/inwpvs9il30f1sd9arjkxg81acnw87yy-edgedb-server/lib/python3.11/site-packages/edb/edgeql/compiler/stmt.py\", line 137, in compile_SelectQuery\n    stmt.where = clauses.compile_where_clause(expr.where, ctx=sctx)\n                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/nix/store/inwpvs9il30f1sd9arjkxg81acnw87yy-edgedb-server/lib/python3.11/site-packages/edb/edgeql/compiler/clauses.py\", line 55, in compile_where_clause\n    ir_expr = dispatch.compile(where, ctx=subctx)\n              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/nix/store/inwpvs9il30f1sd9arjkxg81acnw87yy-edgedb-server/lib/python3.11/functools.py\", line 909, in wrapper\n    return dispatch(args[0].__class__)(*args, **kw)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/nix/store/inwpvs9il30f1sd9arjkxg81acnw87yy-edgedb-server/lib/python3.11/site-packages/edb/edgeql/compiler/expr.py\", line 135, in compile_BinOp\n    op_node = func.compile_operator(\n              ^^^^^^^^^^^^^^^^^^^^^^\n  File \"/nix/store/inwpvs9il30f1sd9arjkxg81acnw87yy-edgedb-server/lib/python3.11/site-packages/edb/edgeql/compiler/func.py\", line 363, in compile_operator\n    arg_ir = polyres.compile_arg(\n             ^^^^^^^^^^^^^^^^^^^^\n  File \"/nix/store/inwpvs9il30f1sd9arjkxg81acnw87yy-edgedb-server/lib/python3.11/site-packages/edb/edgeql/compiler/polyres.py\", line 607, in compile_arg\n    arg_ir = dispatch.compile(arg_ql, ctx=argctx)\n             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/nix/store/inwpvs9il30f1sd9arjkxg81acnw87yy-edgedb-server/lib/python3.11/functools.py\", line 909, in wrapper\n    return dispatch(args[0].__class__)(*args, **kw)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/nix/store/inwpvs9il30f1sd9arjkxg81acnw87yy-edgedb-server/lib/python3.11/site-packages/edb/edgeql/compiler/expr.py\", line 77, in compile_Path\n    return stmt.maybe_add_view(setgen.compile_path(expr, ctx=ctx), ctx=ctx)\n                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/nix/store/inwpvs9il30f1sd9arjkxg81acnw87yy-edgedb-server/lib/python3.11/site-packages/edb/edgeql/compiler/setgen.py\", line 477, in compile_path\n    path_tip = ptr_step_set(\n               ^^^^^^^^^^^^^\n  File \"/nix/store/inwpvs9il30f1sd9arjkxg81acnw87yy-edgedb-server/lib/python3.11/site-packages/edb/edgeql/compiler/setgen.py\", line 642, in ptr_step_set\n    ptrcls, path_id_ptrcls = resolve_ptr_with_intersections(\n                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/nix/store/inwpvs9il30f1sd9arjkxg81acnw87yy-edgedb-server/lib/python3.11/site-packages/edb/edgeql/compiler/setgen.py\", line 718, in resolve_ptr_with_intersections\n    raise errors.InvalidReferenceError(msg, context=source_context)\nedb.errors.InvalidReferenceError: invalid property reference on a primitive type expression\n"

Tried on v4.2, v4.7, v5-beta3

@MrFoxPro
Copy link
Contributor Author

probably wrapping into select <json>(..) fixes this

@aljazerzen
Copy link
Contributor

This issue is hard to read because you've edited the original question. The problem is with this EdgeQL query:

select <json>OtpPhoneRequest { id, phone } filter .id = {}
> Error: InvalidReferenceError: invalid property reference on a primitive type expression (on line 1, column 57)

It is saying that field id does not exist on type json. This happens because you first cast to json and then filter.

This is what you wanted to do:

select <json>(select OtpPhoneRequest { id, phone } filter .id = {})

Although the bindings could print an nicer error message that would look like this:

Error:
    select <json>OtpPhoneRequest { id, phone } filter .id = {}
                                                      ^^^
                                                      invalid reference

    Details: invalid property reference on a primitive type expression

@aljazerzen
Copy link
Contributor

Ref #282

aljazerzen added a commit that referenced this issue Apr 18, 2024
aljazerzen added a commit that referenced this issue Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants