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

unimplemented! in typeinfo blocks to get any detail about error #1408

Closed
gzp79 opened this issue Aug 27, 2021 · 3 comments · Fixed by #1848
Closed

unimplemented! in typeinfo blocks to get any detail about error #1408

gzp79 opened this issue Aug 27, 2021 · 3 comments · Fixed by #1848
Labels
db:any Concerns the runtime-polymorphic `Any` driver

Comments

@gzp79
Copy link

gzp79 commented Aug 27, 2021

For any db in impl_any_type macro, the type_info is unimplemented. It makes it really hard to get real errors with type issues.

It'd be good to have at least some temp solution, some placeholder, that won't panic but returns 'this part of error report will be improved later`. Now I have to go into sqlx source and guess what could be the isssue instead of just reading the error message.

Some more context:
With postgersl backend the table used SERIAL as an id (i32) but I tried to read it back as an i64. After altering the type to BigSerial all was working fine, but it took me a while to realize SERIAL is using a smaller integer type.

@abonander
Copy link
Collaborator

abonander commented Sep 1, 2021

So were you trying to call <i64 as <Type<Any>>::type_info() directly, maybe to print the return value?

As the comment on the macro says, the Any driver should never be invoking this method directly, so if it is then it's a bug. Otherwise, the only way it would panic would be if you called it manually.

The issue here is that the Any driver requires the context of the currently running database to construct an AnyTypeInfo:

pub(crate) enum AnyTypeInfoKind {
#[cfg(feature = "postgres")]
Postgres(PgTypeInfo),
#[cfg(feature = "mysql")]
MySql(MySqlTypeInfo),
#[cfg(feature = "sqlite")]
Sqlite(SqliteTypeInfo),
#[cfg(feature = "mssql")]
Mssql(MssqlTypeInfo),
}

However, Type::type_info() has no access to such context, thus the panic.

It's poor API design on our part, but I don't know how we can fix this easily.

@abonander abonander added the db:any Concerns the runtime-polymorphic `Any` driver label Sep 1, 2021
@gzp79
Copy link
Author

gzp79 commented Sep 1, 2021

It was called by the engine is some error reporting function. Once I get back to a computer I'll add the backtrace, but to reproduce the query_as function should be called where the db type does not match to the rust type sg like:

let row: (i61,)=sqlx::query_as("select 'foo'").fetch_one(&pool);

@gzp79
Copy link
Author

gzp79 commented Sep 7, 2021

code:

            let pool = sqlx::any::AnyPoolOptions::new().max_connections(5).connect(&cns).await.unwrap();
            let q : (i64,) = sqlx::query_as("select '1'").fetch_one(&pool).await.unwrap();
            log::trace!("{:?}", q);

error:

running 1 test
thread 'create_db' panicked at 'not implemented', \.cargo\registry\src\gh.neting.cc-1ecc6299db9ec823\sqlx-core-0.5.7\src\any\types.rs:25:1
stack backtrace:
   0: std::panicking::begin_panic_handler
             at /rustc/a49e38e672c60da788360e088f00ad12353e3913\/library\std\src\panicking.rs:517
   1: core::panicking::panic_fmt
             at /rustc/a49e38e672c60da788360e088f00ad12353e3913\/library\core\src\panicking.rs:93
   2: core::panicking::panic
             at /rustc/a49e38e672c60da788360e088f00ad12353e3913\/library\core\src\panicking.rs:50
   3: sqlx_core::any::types::impl$2::type_info
             at \.cargo\registry\src\gh.neting.cc-1ecc6299db9ec823\sqlx-core-0.5.7\src\any\type.rs:12
   4: sqlx_core::error::mismatched_types<sqlx_core::any::database::Any,i64>
             at \.cargo\registry\src\gh.neting.cc-1ecc6299db9ec823\sqlx-core-0.5.7\src\error.rs:143
   5: sqlx_core::row::Row::try_get<sqlx_core::any::row::AnyRow,i64,usize>
             at \.cargo\registry\src\gh.neting.cc-1ecc6299db9ec823\sqlx-core-0.5.7\src\row.rs:124
   6: sqlx_core::from_row::impl$0::from_row<sqlx_core::any::row::AnyRow,i64>
             at \.cargo\registry\src\gh.neting.cc-1ecc6299db9ec823\sqlx-core-0.5.7\src\from_row.rs:112
   7: sqlx_core::query_as::impl$2::fetch_optional::generator$0<sqlx_core::any::database::Any,tuple$<i64>,sqlx_core::any::arguments::AnyArguments,ref$<sqlx_core::pool::Pool<sqlx_core::any::database::Any> > >
             at \.cargo\registry\src\gh.neting.cc-1ecc6299db9ec823\sqlx-core-0.5.7\src\query_as.rs:147
   8: core::future::from_generator::impl$1::poll<sqlx_core::query_as::impl$2::fetch_optional::generator$0>
             at /rustc/a49e38e672c60da788360e088f00ad12353e3913\library\core\src\future\mod.rs:80
   9: sqlx_core::query_as::impl$2::fetch_one::generator$0<sqlx_core::any::database::Any,tuple$<i64>,sqlx_core::any::arguments::AnyArguments,ref$<sqlx_core::pool::Pool<sqlx_core::any::database::Any> > >
             at \.cargo\registry\src\gh.neting.cc-1ecc6299db9ec823\sqlx-core-0.5.7\src\query_as.rs:131
  10: core::future::from_generator::impl$1::poll<sqlx_core::query_as::impl$2::fetch_one::generator$0>
             at /rustc/a49e38e672c60da788360e088f00ad12353e3913\library\core\src\future\mod.rs:80
  11: cookdb::create_db::generator$0
             at .\tests\cookdb.rs:41
  12: core::future::from_generator::impl$1::poll<cookdb::create_db::generator$0>
             at /rustc/a49e38e672c60da788360e088f00ad12353e3913\library\core\src\future\mod.rs:80
  13: tokio::park::thread::impl$5::block_on::closure$0<core::future::from_generator::GenFuture<cookdb::create_db::generator$0> >
             at \.cargo\registry\src\gh.neting.cc-1ecc6299db9ec823\tokio-1.10.1\src\park\thread.rs:263
  14: tokio::coop::with_budget::closure$0<enum$<core::task::poll::Poll<tuple$<> > >,tokio::park::thread::impl$5::block_on::closure$0>
             at \.cargo\registry\src\gh.neting.cc-1ecc6299db9ec823\tokio-1.10.1\src\coop.rs:106
  15: std::thread::local::LocalKey<core::cell::Cell<tokio::coop::Budget> >::try_with<core::cell::Cell<tokio::coop::Budget>,tokio::coop::with_budget::closure$0,enum$<core::task::poll::Poll<tuple$<> > > >
             at /rustc/a49e38e672c60da788360e088f00ad12353e3913\library\std\src\thread\local.rs:399
  16: std::thread::local::LocalKey<core::cell::Cell<tokio::coop::Budget> >::with<core::cell::Cell<tokio::coop::Budget>,tokio::coop::with_budget::closure$0,enum$<core::task::poll::Poll<tuple$<> > > >
             at /rustc/a49e38e672c60da788360e088f00ad12353e3913\library\std\src\thread\local.rs:375
  17: tokio::coop::with_budget
             at \.cargo\registry\src\gh.neting.cc-1ecc6299db9ec823\tokio-1.10.1\src\coop.rs:99
  18: tokio::coop::budget
             at \.cargo\registry\src\gh.neting.cc-1ecc6299db9ec823\tokio-1.10.1\src\coop.rs:76
  19: tokio::park::thread::CachedParkThread::block_on<core::future::from_generator::GenFuture<cookdb::create_db::generator$0> >
             at \.cargo\registry\src\gh.neting.cc-1ecc6299db9ec823\tokio-1.10.1\src\park\thread.rs:263
  20: tokio::runtime::enter::Enter::block_on<core::future::from_generator::GenFuture<cookdb::create_db::generator$0> >
             at \.cargo\registry\src\gh.neting.cc-1ecc6299db9ec823\tokio-1.10.1\src\runtime\enter.rs:151
  21: tokio::runtime::thread_pool::ThreadPool::block_on<core::future::from_generator::GenFuture<cookdb::create_db::generator$0> >
             at \.cargo\registry\src\gh.neting.cc-1ecc6299db9ec823\tokio-1.10.1\src\runtime\thread_pool\mod.rs:71
  22: tokio::runtime::Runtime::block_on<core::future::from_generator::GenFuture<cookdb::create_db::generator$0> >
             at \.cargo\registry\src\gh.neting.cc-1ecc6299db9ec823\tokio-1.10.1\src\runtime\mod.rs:452
  23: cookdb::create_db
             at .\tests\cookdb.rs:51
  24: cookdb::create_db::closure$0
             at .\tests\cookdb.rs:10
  25: core::ops::function::FnOnce::call_once<cookdb::create_db::closure$0,tuple$<> >
             at /rustc/a49e38e672c60da788360e088f00ad12353e3913\library\core\src\ops\function.rs:227
  26: core::ops::function::FnOnce::call_once
             at /rustc/a49e38e672c60da788360e088f00ad12353e3913\library\core\src\ops\function.rs:227
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
test create_db ... FAILED

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
db:any Concerns the runtime-polymorphic `Any` driver
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants