-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
query_as! offline mode mismatched types expected struct X, found enum std::option::Option
#1294
Comments
Also having this issue with this version trying to do that command |
Same issue create table balances
(
event_hash BYTEA UNIQUE,
lp_address VARCHAR NOT NULL,
base_address VARCHAR NOT NULL,
counter_address VARCHAR NOT NULL,
base VARCHAR NOT NULL,
counter VARCHAR NOT NULL,
base_volume DECIMAL NOT NULL,
counter_volume DECIMAL NOT NULL,
lp_volume DECIMAL NOT NULL,
timestamp_block INT NOT NULL,
created_at BIGINT NOT NULL,
PRIMARY KEY (lp_address, created_at)
); #[derive(Clone, Debug, serde::Serialize, serde::Deserialize, Eq, PartialEq)]
pub struct BalanceFromDb {
pub event_hash: Option<Vec<u8>>,
pub lp_address: String,
pub base_address: String,
pub counter_address: String,
pub base: String,
pub counter: String,
pub base_volume: Decimal,
pub counter_volume: Decimal,
pub lp_volume: Decimal,
pub timestamp_block: i32,
pub created_at: i64,
} |
Any updates? |
It's a bit annoying but you can use overrides to force nullable/not nullable: https://docs.rs/sqlx/0.5.7/sqlx/macro.query.html#overrides-cheatsheet If you're always compiling in offline mode (with However, arbitrary changes to the query, or even compiling against a development vs production database, or different versions of Postgres, can change the query plan enough to where it breaks nullability inference. In this case what would really help is to provide the output of |
I've used the same database all the time, the only thing ive changed are the queries and have gradually added more. It makes it very difficult to make the |
This happened to me (sqlx 0.5.9, psql 11.14) for a foreign key referencing a primary key defined like this:
The foreign key is defined in another table as:
With this definition there is this compilation error message for an sqlx expected type Adding NOT NULL to the foreign key definition fixed this:
I could change the foreign key definition since the table is still in early development, |
This happened to me ( I have one table and associated structs that works perfectly: CREATE TABLE libraries (
id INTEGER PRIMARY KEY,
/* ... */
); struct DbLibrary {
pub id: i64,
// ...
} Then I added two tables like the previous one, but for those two I got the error |
On sqlite with sqlx version 0.6.2. I have a table defined like this:
This works fine:
However, when I add a unique index to the email column so that two accounts can't have the same email:
I get this error when compiling the exact same query:
I can fix it by casting the id column:
I can also fix it by searching on a different column:
|
I had the same problem, after adding unique constraints to my email and username columns, I was able to add |
I noticed there i a similar issue #93
I am using the latest version of SQLx so I don't believe that issue was solved:
To create the offline bundle and to recreate the error I run:
I'm using the offline package with Postgres with the
sqlx::query_as!
macro and SQLx seems to think every column I have is nullable. So I get a generic error:mismatched types expected struct [i32, String, ..], found enum `std::option::Option
Its a bit random how it happens but its very frustrating when you make all your values
Option< >
eventually it realises and switches back to the opposite error where it expected Option but found an i32 or whatever the underlying struct was.I have noticed the only pattern is when it has this error, every single struct is considered nullable vs incorrect ones singled out out of a list. So you either have SQLx think they are all nullable, or all of them are interpreted as the correct types.
The text was updated successfully, but these errors were encountered: