diesel_cli print-schema: Failed to execute a database query: Error deserializing field 'character_maximum_length': could not convert slice to array #4630
Replies: 5 comments 4 replies
-
Thanks for opening this report. I've tried to reproduce this locally with the same mariadb version installed and with the provided table definition. I cannot trigger the described error, therefore that might be a system specific issue. So from a formal point of view this seems to work as expected, therefore I converted this to a support thread in the discussion forum. As for fixing the actual issue: It's hard to help you there without having access to the exact state your system is in. You can try to execute the query printed by the debug logging and provide the result. Maybe there is something useful in there, maybe not. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the reply. I included the output of the query at the end of this post. Last night I discovered this is not only a problem when running diesel_cli, but it is also breaking an existing unit test I have for a Tauri app, and the app itself when I perform certain queries. The unit tests query the 'transaction' table itself, not the information schema. Strange that the other four tests that hit the exact same table with similar parameters work just fine. I'll try to see what is "special" about the failing unit test and associated query results. Failing that, I'll rebuild my DB and wipe out my cargo packages and try again. In the meantime, here's the stack trace from the failing unit test: running 5 tests thread 'tests::test_transactions_summaries_all_dates' panicked at src/dao.rs:92:10: Query output: MariaDB [investments]> SELECT |
Beta Was this translation helpful? Give feedback.
-
For anyone who stumbles upon this I was able to resolve the unit test and Tauri app issues by reinstalling all the relevant software, and completely rebuilding my Maria DB instance and restoring from a backup script. See below for an overview of the steps: Strangely after all that I still had the same problem with This suggests the root issue is/was not related to the database (software or data) at all, but something with my copy of diesel and/or its mysql integration. I finally resolved the Re-installation / Rebuild Overview:
|
Beta Was this translation helpful? Give feedback.
-
I also ran into this issue (print-schema not working with that exact error message) after changing my migration script. I renamed a table and its primary key, which is also a foreign key in another table. I also use MariaDB but on MacOS 15.5 (aarch64). I also updated MariaDB recently to version 11.8.2 (from 11.7.2), so maybe I only now run into this issue.
I wish I could use Postgres. |
Beta Was this translation helpful? Give feedback.
-
I could reproduce the issue on a similar system as the original reporter. There seems to be an issue with NULL value detection in the diesel code if the MariaDB client library and/or MariaDB is used. In the particular case, character_maximum_length can result in If corresponding code is changed to #[cfg(feature = "mysql_backend")]
impl FromSql<Unsigned<BigInt>, Mysql> for u64 {
#[allow(
clippy::cast_possible_wrap,
clippy::cast_sign_loss,
clippy::cast_possible_truncation
)]
fn from_sql(bytes: MysqlValue<'_>) -> deserialize::Result<Self> {
// should never happen, but seems to be the case with mariadb
if bytes.as_bytes().is_empty() {
return Ok(0); // wrong as it maps NULL to 0, but fixes print-schema
}
let signed: i64 = FromSql::<BigInt, Mysql>::from_sql(bytes)?;
Ok(signed as u64)
}
}
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Setup
Table:
CREATE TABLE
transaction
(id
mediumint(9) NOT NULL AUTO_INCREMENT,date
date NOT NULL,account
char(32) NOT NULL,symbol
char(32) NOT NULL,security
char(128) NOT NULL,action
char(32) NOT NULL,memo
char(128) DEFAULT NULL,price
decimal(14,6) DEFAULT NULL,adj_price
decimal(14,6) DEFAULT NULL,shares
decimal(14,6) DEFAULT NULL,adj_shares
decimal(14,6) DEFAULT NULL,amount
decimal(10,2) NOT NULL,cost_basis
decimal(10,2) DEFAULT NULL,type
char(16) NOT NULL,dt
datetime NOT NULL,PRIMARY KEY (
id
),KEY
fk_action_type
(action
,type
),CONSTRAINT
fk_action_type
FOREIGN KEY (action
,type
) REFERENCESaction_types
(action
,type
))
Versions
Feature Flags
Problem Description
Running: diesel print-schema
gives the following error with the above table:
"Failed to execute a database query: Error deserializing field 'character_maximum_length': could not convert slice to array"
What are you trying to accomplish?
Generate a schema file from a single table in an existing MariaDB database. Note that this worked on earlier iterations of the table structure and versions of all software involved.
What is the expected output?
No errors and a 'schema.rs' file with the schema for the 'transaction' table.
What is the actual output?
"Failed to execute a database query: Error deserializing field 'character_maximum_length': could not convert slice to array"
Are you seeing any additional errors?
I was able to instrument the source with some print! statements and get the more specific error of:
QueryError(DeserializationError(DeserializeFieldError { field_name: Some("character_maximum_length"), error: TryFromSliceError(()) }))
Additionally from print! debugging, the query in question appears to be:
SELECT
information_schema
.columns
.column_name
,information_schema
.columns
.column_type
, ?,information_schema
.columns
.is_nullable
,information_schema
.columns
.character_maximum_length
, NULLIF(information_schema
.columns
.column_comment
, ?) FROMinformation_schema
.columns
WHERE ((information_schema
.columns
.table_name
= ?) AND (information_schema
.columns
.table_schema
= ?)) ORDER BYinformation_schema
.columns
.ordinal_position
-- binds: [None, "", "transaction", "investments"]Steps to reproduce
Run:
diesel print-schema
against the 'transaction' table above. Note that this shouldn't require any data in the transaction table itself as the failing query goes against an information schema table.Checklist
closed if this is not the case)
Beta Was this translation helpful? Give feedback.
All reactions