edgedb / edgedb-rust

The official Rust binding for EdgeDB
https://edgedb.com
Apache License 2.0
214 stars 26 forks source link

Problems with handling polymorphic query #15

Closed vpetrovykh closed 4 years ago

vpetrovykh commented 4 years ago

Currently if I try this with the tutorial database I get an error:

SELECT User {
    name,
    email,
    last_post := (
        SELECT .<author[IS Media] {
            [IS Text].title,
        }
    ),
}
FILTER .email = 'alice@tutorial.com';

The culprit seems to be specifically the polymorphic property "title" (if I fetch some common property of Media things work fine). If I don't use rust REPL this query works fine.

1st1 commented 4 years ago

I get an error

Please copy/paste error texts for issues like this.

vpetrovykh commented 4 years ago
queries> SELECT User {
........     name,
........     email,
........     last_post := (
........         SELECT .<author[IS Media] {
........             [IS Text].title,
........         }
........     ),
........ }
........ FILTER .email = 'alice@tutorial.com';
StreamErr {
    source: DecodeErr {
        source: Underflow {
            backtrace: Backtrace(
                   0:     0x5580c075ebdd - backtrace::backtrace::libunwind::trace::h8044112bfb1bd93a
                                               at /home/victor/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.44/src/backtrace/libunwind.rs:86
                                           backtrace::backtrace::trace_unsynchronized::h94fc47d7c828a364
                                               at /home/victor/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.44/src/backtrace/mod.rs:66
                   1:     0x5580c075eb5e - backtrace::backtrace::trace::hd9ba7b5d5902669a
                                               at /home/victor/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.44/src/backtrace/mod.rs:53
                   2:     0x5580c07515fd - backtrace::capture::Backtrace::create::h6cb85277e08471cc
                                               at /home/victor/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.44/src/capture.rs:164
                   3:     0x5580c0751515 - backtrace::capture::Backtrace::new::hd589c7b0b4a7b8c3
                                               at /home/victor/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.44/src/capture.rs:128
                   4:     0x5580c0700305 - <snafu::backtrace_shim::Backtrace as snafu::GenerateBacktrace>::generate::h57305acaa90df264
                                               at /home/victor/.cargo/registry/src/github.com-1ecc6299db9ec823/snafu-0.6.2/src/backtrace_shim.rs:15
                                           edgedb_protocol::errors::Underflow::fail::had2b50b3eac9b7ac
                                               at edgedb-protocol/src/errors.rs:9
                   5:     0x5580c06eec04 - <edgedb_protocol::codec::Object as edgedb_protocol::codec::Codec>::decode::ha7796c581ed008a2
                                               at edgedb-protocol/src/codec.rs:557
                   6:     0x5580c06e8e80 - <dyn edgedb_protocol::codec::Codec>::decode_value::h25e569ad4c2f419e
                                               at edgedb-protocol/src/codec.rs:207
                   7:     0x5580c06f0bf1 - <edgedb_protocol::codec::SetCodec as edgedb_protocol::codec::Codec>::decode::h7f86605fea8916c2
                                               at edgedb-protocol/src/codec.rs:681
                   8:     0x5580c06e8e80 - <dyn edgedb_protocol::codec::Codec>::decode_value::h25e569ad4c2f419e
                                               at edgedb-protocol/src/codec.rs:207
                   9:     0x5580c06eed52 - <edgedb_protocol::codec::Object as edgedb_protocol::codec::Codec>::decode::ha7796c581ed008a2
                                               at edgedb-protocol/src/codec.rs:561
                  10:     0x5580c06e8e80 - <dyn edgedb_protocol::codec::Codec>::decode_value::h25e569ad4c2f419e
                                               at edgedb-protocol/src/codec.rs:207
                  11:     0x5580c0388dad - <alloc::sync::Arc<dyn edgedb_protocol::codec::Codec> as edgedb::reader::Decode>::decode::h90a529680f2a8f2e
                                               at edgedb-repl/src/reader.rs:83
                  12:     0x5580c0293023 - <edgedb::reader::QueryResponse<T,D> as futures_core::stream::Stream>::poll_next::h312d73e7dbff801d
                                               at edgedb-repl/src/reader.rs:220
                  13:     0x5580c032d95a - <async_std::stream::stream::next::NextFuture<T> as core::future::future::Future>::poll::hff5d1571104893c1
                                               at /home/victor/.cargo/registry/src/github.com-1ecc6299db9ec823/async-std-1.5.0/src/stream/stream/next.rs:17
                  14:     0x5580c037651a - std::future::poll_with_tls_context::h4cdf9ecb6426463f
                                               at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8/src/libstd/future.rs:99
                  15:     0x5580c02c8f2d - edgedb::print::format_rows_buf::{{closure}}::hfdf9d6965fac3fba
                                               at edgedb-repl/src/print/mod.rs:77
                  16:     0x5580c0381658 - <std::future::GenFuture<T> as core::future::future::Future>::poll::ha2b5d20c4eef769f
                                               at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8/src/libstd/future.rs:43
                  17:     0x5580c0376faa - std::future::poll_with_tls_context::h7616e15f978aec92
                                               at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8/src/libstd/future.rs:99
                  18:     0x5580c02cbd69 - edgedb::print::print_to_stdout::{{closure}}::h72eaeab9f94d4aa3
                                               at edgedb-repl/src/print/mod.rs:139
                  19:     0x5580c037d688 - <std::future::GenFuture<T> as core::future::future::Future>::poll::h3f42e2c5f24a2ba6
                                               at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8/src/libstd/future.rs:43
                  20:     0x5580c0377bda - std::future::poll_with_tls_context::h8c7f08387fbb871e
                                               at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8/src/libstd/future.rs:99
                  21:     0x5580c02337f2 - edgedb::client::_interactive_main::{{closure}}::h3e396a47e0fa3b08
                                               at edgedb-repl/src/client.rs:328
                  22:     0x5580c037ecfa - <std::future::GenFuture<T> as core::future::future::Future>::poll::h6039daa830d8521c
                                               at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8/src/libstd/future.rs:43
                  23:     0x5580c03790ea - std::future::poll_with_tls_context::hd2f48bc82aae673c
                                               at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8/src/libstd/future.rs:99
                  24:     0x5580c022cd74 - edgedb::client::interactive_main::{{closure}}::hc3fb89fd077ceac1
                                               at edgedb-repl/src/client.rs:156
                  25:     0x5580c03819ca - <std::future::GenFuture<T> as core::future::future::Future>::poll::ha5bb76ed2368c5f9
                                               at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8/src/libstd/future.rs:43
                  26:     0x5580c03769ea - std::future::poll_with_tls_context::h64e2b42be933ee54
                                               at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8/src/libstd/future.rs:99
                  27:     0x5580c03325c7 - async_std::task::builder::Builder::spawn::{{closure}}::h94303ab2f136613b
                                               at /home/victor/.cargo/registry/src/github.com-1ecc6299db9ec823/async-std-1.5.0/src/task/builder.rs:64
                  28:     0x5580c038361a - <std::future::GenFuture<T> as core::future::future::Future>::poll::hda201b8d5f39da96
                                               at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8/src/libstd/future.rs:43
                  29:     0x5580c01b5f26 - async_task::raw::RawTask<F,R,S,T>::run::hb17fc223db60321a
                                               at /home/victor/.cargo/registry/src/github.com-1ecc6299db9ec823/async-task-1.3.1/src/raw.rs:505
                  30:     0x5580c07effff - async_task::task::Task<T>::run::h9f94ddae2c675862
                                               at /home/victor/.cargo/registry/src/github.com-1ecc6299db9ec823/async-task-1.3.1/src/task.rs:239
                  31:     0x5580c080f61f - async_std::task::builder::Runnable::run::{{closure}}::{{closure}}::hb60181c48b192844
                                               at /home/victor/.cargo/registry/src/github.com-1ecc6299db9ec823/async-std-1.5.0/src/task/builder.rs:81
                  32:     0x5580c080e4cb - async_std::utils::abort_on_panic::hffe5af82060ef7cb
                                               at /home/victor/.cargo/registry/src/github.com-1ecc6299db9ec823/async-std-1.5.0/src/utils.rs:16
                  33:     0x5580c080f64e - async_std::task::builder::Runnable::run::{{closure}}::h27133293357b4b5a
                                               at /home/victor/.cargo/registry/src/github.com-1ecc6299db9ec823/async-std-1.5.0/src/task/builder.rs:81
                  34:     0x5580c082d98f - async_std::task::task::Task::set_current::{{closure}}::h857fa935e6e61e50
                                               at /home/victor/.cargo/registry/src/github.com-1ecc6299db9ec823/async-std-1.5.0/src/task/task.rs:129
                  35:     0x5580c08326b7 - std::thread::local::LocalKey<T>::try_with::h872312af7d339ed2
                                               at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8/src/libstd/thread/local.rs:262
                  36:     0x5580c0831c38 - std::thread::local::LocalKey<T>::with::h27ab2a7b829ab86a
                                               at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8/src/libstd/thread/local.rs:239
                  37:     0x5580c082d8c9 - async_std::task::task::Task::set_current::h82403aa229e05dbb
                                               at /home/victor/.cargo/registry/src/github.com-1ecc6299db9ec823/async-std-1.5.0/src/task/task.rs:124
                  38:     0x5580c080f5d6 - async_std::task::builder::Runnable::run::h5964ffdda21bce5b
                                               at /home/victor/.cargo/registry/src/github.com-1ecc6299db9ec823/async-std-1.5.0/src/task/builder.rs:81
                  39:     0x5580c07ff2a0 - async_std::task::executor::pool::main_loop::hbfee0369051ff24e
                                               at /home/victor/.cargo/registry/src/github.com-1ecc6299db9ec823/async-std-1.5.0/src/task/executor/pool.rs:114
                  40:     0x5580c07f4e19 - core::ops::function::FnOnce::call_once::h003ce8b6cb983482
                                               at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8/src/libcore/ops/function.rs:232
                  41:     0x5580c080e447 - async_std::utils::abort_on_panic::h9ecdd8b2a806d53b
                                               at /home/victor/.cargo/registry/src/github.com-1ecc6299db9ec823/async-std-1.5.0/src/utils.rs:16
                  42:     0x5580c07fe9b0 - async_std::task::executor::pool::POOL::{{closure}}::{{closure}}::h20bb84578b433de5
                                               at /home/victor/.cargo/registry/src/github.com-1ecc6299db9ec823/async-std-1.5.0/src/task/executor/pool.rs:46
                  43:     0x5580c07f1a12 - std::sys_common::backtrace::__rust_begin_short_backtrace::h6b78b59b19621b64
                                               at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8/src/libstd/sys_common/backtrace.rs:136
                  44:     0x5580c07e8aa3 - std::thread::Builder::spawn_unchecked::{{closure}}::{{closure}}::h175ea7b5aaa30a21
                                               at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8/src/libstd/thread/mod.rs:469
                  45:     0x5580c07e08f1 - <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once::haa20c3977be75c47
                                               at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8/src/libstd/panic.rs:318
                  46:     0x5580c082b860 - std::panicking::try::do_call::h340b245303f0173b
                                               at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8/src/libstd/panicking.rs:292
                  47:     0x5580c08aceaa - __rust_maybe_catch_panic
                                               at src/libpanic_unwind/lib.rs:78
                  48:     0x5580c082b6c8 - std::panicking::try::had23306532e56262
                                               at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8/src/libstd/panicking.rs:270
                  49:     0x5580c07e0a73 - std::panic::catch_unwind::hb64cca2998eafd32
                                               at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8/src/libstd/panic.rs:394
                  50:     0x5580c07e8892 - std::thread::Builder::spawn_unchecked::{{closure}}::h6a7b4561e9ba817b
                                               at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8/src/libstd/thread/mod.rs:468
                  51:     0x5580c07f4d34 - core::ops::function::FnOnce::call_once{{vtable.shim}}::h2b71f264eb035595
                                               at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8/src/libcore/ops/function.rs:232
                  52:     0x5580c08971ff - <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once::h7bfd6e98bcf6c67e
                                               at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8/src/liballoc/boxed.rs:1022
                  53:     0x5580c08ac000 - <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once::h9979661149bbc525
                                               at /rustc/5e1a799842ba6ed4a57e91f7ab9435947482f7d8/src/liballoc/boxed.rs:1022
                                           std::sys_common::thread::start_thread::had0bb4166c065276
                                               at src/libstd/sys_common/thread.rs:13
                                           std::sys::unix::thread::Thread::new::thread_start::hbc75223688f972da
                                               at src/libstd/sys/unix/thread.rs:80
                  54:     0x7facbfe1c448 - start_thread
                  55:     0x7facbfb3369f - __clone
                  56:                0x0 - <unknown>
                ,
            ),
        },
    },
}
{
tailhook commented 4 years ago

It works for me with the schema from the tutorial. So I need exact data which fails for you.

vpetrovykh commented 4 years ago

It happens in the tutorial database, so the setup script should get you the right data: https://github.com/edgedb/tutorial/blob/master/edgedb_tutorial/resources/queries_setup.edgeql

tailhook commented 4 years ago

It's not because of polymorphic query, it's because of title can be NULL. I've fixed it for objects, but I'm not sure about other types: sets, arrays, tuples.

tailhook commented 4 years ago

For now it looks like it's possible only that fields of objects can have optional values. So this issue should have been fixed.