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

ValueTypeErr on array with none, [ db: postgres ] #2354

Open
leefordjudes opened this issue Sep 11, 2024 · 0 comments
Open

ValueTypeErr on array with none, [ db: postgres ] #2354

leefordjudes opened this issue Sep 11, 2024 · 0 comments

Comments

@leefordjudes
Copy link

Description

value type error occurs on executing array type with none,

Cargo.toml

[package]
name = "seaorm-intarray"
version = "0.1.0"
edition = "2021"

[dependencies]
sea-orm = { version = "1.0.1", features = ["sqlx-postgres", "runtime-tokio-native-tls"] }
tokio ={ version = "1.40.0", features = ["macros","rt-multi-thread"]}
serde_json ={ version = "*" }

Array with int raises error

main.rs

use sea_orm::{Database, DatabaseBackend, FromQueryResult, JsonValue, Statement};

#[tokio::main]
async fn main() -> Result<(), String> {
    let db_uri = "postgresql://postgres:[email protected]:5432/vmdb";
    let db = Database::connect(db_uri).await.unwrap();
    let data = sea_orm::Value::Array(
        sea_orm::sea_query::ArrayType::Int,
        Some(Box::new(vec![
            sea_orm::Value::Int(None),
            sea_orm::Value::Int(Some(1)),
        ])),
    );
    let stmt = Statement::from_sql_and_values(
        DatabaseBackend::Postgres,
        "select id, name from account where id = any($1)",
        [data],
    );
    let res = JsonValue::find_by_statement(stmt).all(&db).await.unwrap();
    println!("{:?}", serde_json::to_string_pretty(&res).unwrap());
    Ok(())
}

Error

Compiling seaorm-intarray v0.1.0 (D:\wf\seaorm-intarray) Finished `dev` profile [unoptimized + debuginfo] target(s) in 1.69s Running `target\debug\seaorm-intarray.exe` thread 'main' panicked at C:\Users\admin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\sea-query-0.31.0\src\value.rs:256:27: called `Result::unwrap()` on an `Err` value: ValueTypeErr stack backtrace: 0: std::panicking::begin_panic_handler at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library\std\src\panicking.rs:652 1: core::panicking::panic_fmt at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library\core\src\panicking.rs:72 2: core::result::unwrap_failed at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library\core\src\result.rs:1679 3: enum2$ >::unwrap at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23\library\core\src\result.rs:1102 4: sea_query::value::ValueType::unwrap at C:\Users\admin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\sea-query-0.31.0\src\value.rs:256 5: enum2$::unwrap at C:\Users\admin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\sea-query-0.31.0\src\value.rs:312 6: sea_query::value::with_array::impl$31::try_from::closure$0 at C:\Users\admin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\sea-query-0.31.0\src\value.rs:875 7: core::iter::adapters::map::map_fold::closure$0,i32,tuple$<>,sea_query::value::with_array::impl$31::try_from::closure_env$0,core::iter::traits::iterator::Iterator::for_each::call::closure_env$0,alloc::alloc::Global,tuple$<>,core::iter::adapters::map::map_fold::closure_env$0,i32,tuple$<>,sea_query::value::with_array::impl$31::try_from::closure_env$0 at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23\library\alloc\src\vec\into_iter.rs:312 9: core::iter::adapters::map::impl$2::fold,alloc::alloc::Global>,sea_query::value::with_array::impl$31::try_from::closure_env$0,tuple$<>,core::iter::traits::iterator::Iterator::for_each: at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23\library\core\src\iter\adapters\map.rs:129 10: core::iter::traits::iterator::Iterator::for_each,alloc::alloc::Global>,sea_query::value::with_array::impl$31::try_from::closure_env$0 >,alloc::vec::impl$20: at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23\library\core\src\iter\traits\iterator.rs:818 11: alloc::vec::Vec::extend_trusted,alloc::alloc::Global>,sea_query::value::with_array::impl$31::try_from::closure at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23\library\alloc\src\vec\mod.rs:3096 12: alloc::vec::spec_extend::impl$1::spec_extend,alloc::alloc::Global>,sea_query::value::with_array::impl$31::try_from::closure_env$0 >,alloc::alloc::Global at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23\library\alloc\src\vec\spec_extend.rs:26 13: alloc::vec::spec_from_iter_nested::impl$1::from_iter,alloc::alloc::Global>,sea_query::value::with_array::impl$31::try_from::closure_env$0 > > at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23\library\alloc\src\vec\spec_from_iter_nested.rs:62 14: alloc::vec::in_place_collect::impl$1::from_iter,alloc::alloc::Global>,sea_query::value::with_array::impl$31::try_from::closure_env$0 > > at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23\library\alloc\src\vec\in_place_collect.rs:245 15: alloc::vec::impl$15::from_iter,alloc::alloc::Global>,sea_query::value::with_array::impl$31::try_from::closure_env$0 > > at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23\library\alloc\src\vec\mod.rs:2970 16: core::iter::traits::iterator::Iterator::collect,alloc::alloc::Global>,sea_query::value::with_array::impl$31::try_from::closure_env$0 >,alloc::vec::Vec at C:\Users\admin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\sea-query-0.31.0\src\value.rs:875 18: sea_query::value::impl$9::try_from > at C:\Users\admin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\sea-query-0.31.0\src\value.rs:458 19: sea_query::value::ValueType::expect > > > at C:\Users\admin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\sea-query-0.31.0\src\value.rs:260 20: enum2$::expect > > > at C:\Users\admin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\sea-query-0.31.0\src\value.rs:319 21: sea_query_binder::sqlx_postgres::impl$0::into_arguments at C:\Users\admin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\sea-query-binder-0.6.0\src\sqlx_postgres.rs:150 22: core::ops::function::FnOnce::call_once > at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23\library\core\src\ops\function.rs:250 23: enum2$ >::map at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23\library\core\src\option.rs:1075 24: sqlx_core::query::impl$0::take_arguments at C:\Users\admin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\sqlx-core-0.7.4\src\query.rs:63 25: sqlx_postgres::connection::executor::impl$1::fetch_many > at C:\Users\admin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\sqlx-postgres-0.7.4\src\connection\executor.rs:373 26: sqlx_core::executor::Executor::fetch,sqlx_core::query::Query > at C:\Users\admin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\sqlx-core-0.7.4\src\executor.rs:76 27: sqlx_core::executor::Executor::fetch_all,sqlx_core::query::Query > at C:\Users\admin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\sqlx-core-0.7.4\src\executor.rs:111 28: sqlx_core::query::impl$3::fetch_all::async_fn$0 > at C:\Users\admin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\sqlx-core-0.7.4\src\query.rs:219 29: sea_orm::driver::sqlx_postgres::impl$3::query_all::async_fn$0::async_block$0 at C:\Users\admin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\sea-orm-1.0.1\src\driver\sqlx_postgres.rs:161 30: sea_orm::driver::sqlx_postgres::impl$3::query_all::async_fn$0 at C:\Users\admin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\sea-orm-1.0.1\src\driver\sqlx_postgres.rs:154 31: sea_orm::database::db_connection::impl$13::query_all::async_block$0::async_block$0 at C:\Users\admin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\sea-orm-1.0.1\src\database\db_connection.rs:196 32: sea_orm::database::db_connection::impl$13::query_all::async_block$0 at C:\Users\admin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\sea-orm-1.0.1\src\database\db_connection.rs:189 33: core::future::future::impl$1::poll,enum2$ > > > >,core::marker: at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23\library\core\src\future\future.rs:123 34: sea_orm::executor::select::impl$8::all::async_fn$0 >,enum2$ > at C:\Users\admin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\sea-orm-1.0.1\src\executor\select.rs:969 35: seaorm_intarray::main::async_block$0 at .\src\main.rs:20 36: core::future::future::impl$1::poll,alloc::alloc::Global> > at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23\library\core\src\future\future.rs:123 37: tokio::runtime::park::impl$4::block_on::closure$0,alloc::alloc::Global> > > at C:\Users\admin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\tokio-1.40.0\src\runtime\park.rs:281 38: tokio::runtime::coop::with_budget at C:\Users\admin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\tokio-1.40.0\src\runtime\coop.rs:107 39: tokio::runtime::coop::budget at C:\Users\admin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\tokio-1.40.0\src\runtime\coop.rs:73 40: tokio::runtime::park::CachedParkThread::block_on,alloc::alloc::Global> > > at C:\Users\admin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\tokio-1.40.0\src\runtime\park.rs:281 41: tokio::runtime::context::blocking::BlockingRegionGuard::block_on,alloc::alloc::Global> > > at C:\Users\admin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\tokio-1.40.0\src\runtime\context\blocking.rs:66 42: tokio::runtime::scheduler::multi_thread::impl$0::block_on::closure$0,alloc::alloc::Global> > > at C:\Users\admin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\tokio-1.40.0\src\runtime\scheduler\multi_thread\mod.rs:87 43: tokio::runtime::context::runtime::enter_runtime,alloc::alloc::Global> > >,enum2$,alloc::alloc::Global> > > at C:\Users\admin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\tokio-1.40.0\src\runtime\scheduler\multi_thread\mod.rs:86 45: tokio::runtime::runtime::Runtime::block_on_inner,alloc::alloc::Global> > > at C:\Users\admin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\tokio-1.40.0\src\runtime\runtime.rs:363 46: tokio::runtime::runtime::Runtime::block_on > at C:\Users\admin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\tokio-1.40.0\src\runtime\runtime.rs:333 47: seaorm_intarray::main at .\src\main.rs:22 48: core::ops::function::FnOnce::call_once,alloc::string::String> > (*)(),tuple$<> > at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23\library\core\src\ops\function.rs:250 note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. error: process didn't exit successfully: `target\debug\seaorm-intarray.exe` (exit code: 101)
  • The terminal process "C:\Users\admin.cargo\bin\cargo.exe 'run', '--package', 'seaorm-intarray', '--bin', 'seaorm-intarray'" terminated with exit code: 101.
  • Terminal will be reused by tasks, press any key to close it.

Array with int without none works good

use sea_orm::{Database, DatabaseBackend, FromQueryResult, JsonValue, Statement};
#[tokio::main]
async fn main() -> Result<(), String> {
    let db_uri = "postgresql://postgres:[email protected]:5432/velavanmedical";
    let db = Database::connect(db_uri).await.unwrap();
    let data = sea_orm::Value::Array(
        sea_orm::sea_query::ArrayType::Int,
        Some(Box::new(vec![
            sea_orm::Value::Int(Some(2)),
            sea_orm::Value::Int(Some(1)),
        ])),
    );
    let stmt = Statement::from_sql_and_values(
        DatabaseBackend::Postgres,
        "select id, name from account where id = any($1)",
        [data],
    );
    let res = JsonValue::find_by_statement(stmt).all(&db).await.unwrap();
    println!("{:?}", serde_json::to_string_pretty(&res).unwrap());
    Ok(())
}

Output

Compiling seaorm-intarray v0.1.0 (D:\wf\seaorm-intarray) Finished `dev` profile [unoptimized + debuginfo] target(s) in 1.72s Running `target\debug\seaorm-intarray.exe` "[\n {\n \"id\": 1,\n \"name\": \"Cash\"\n },\n {\n \"id\": 2,\n \"name\": \"Sales\"\n }\n]"

Steps to Reproduce

  1. follow the above code

Expected Behavior

should work for array with int and none,
because the following query with null is works good in postgres

select id, name from account where id=any(ARRAY[NULL, 1, 2]);
select id, name from account where id in (NULL, 1, 2);

image

Actual Behavior

raises ValueTypeErr

Versions

cargo toml included

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

1 participant