Closed josecelano closed 8 months ago
I've tested it with version v0.7.3 but it does not work either.
I've just realized that the log level ERROR
in the log record does not mean there was an error in the SQL query. It means the query was logged because the global logging level wis ERROR
and the configuration says statements should be logged when glogal loging level is ERROR
2023-12-20T14:05:36.189980850+00:00 [sqlx::query][ERROR] SELECT version, checksum FROM …; rows affected: 0, rows returned: 1, elapsed: 35.472µs
SELECT
version,
checksum
FROM
_sqlx_migrations
ORDER BY
version
The functions log_statements
and log_slow_statements
only specified when you want to log the queries regardless of the query failing or not.
The following configuration:
connection_options
.log_statements(log::LevelFilter::Debug)
.log_slow_statements(log::LevelFilter::Warn, Duration::from_secs(1));
means you want to log all statements when the global logging level is Debug
and you want to log slow statements when the global logging level is Warn
.
connection_options.log_statements(log::LevelFilter::Error)
does not mean you want to log failing statements as I was supposing.
This is the code:
pub trait ConnectOptions: 'static + Send + Sync + FromStr<Err = Error> + Debug + Clone {
type Connection: Connection + ?Sized;
/// Establish a new database connection with the options specified by `self`.
fn connect(&self) -> BoxFuture<'_, Result<Self::Connection, Error>>
where
Self::Connection: Sized;
/// Log executed statements with the specified `level`
fn log_statements(&mut self, level: LevelFilter) -> &mut Self;
/// Log executed statements with a duration above the specified `duration`
/// at the specified `level`.
fn log_slow_statements(&mut self, level: LevelFilter, duration: Duration) -> &mut Self;
/// Entirely disables statement logging (both slow and regular).
fn disable_statement_logging(&mut self) -> &mut Self {
self.log_statements(LevelFilter::Off)
.log_slow_statements(LevelFilter::Off, Duration::default())
}
}
Bug Description
When I enable logging for statements with log level
Error
I get some errors for queries that do not fail:This is the way I enable logging:
If I run the queries manually, they do not fail.
Minimal Reproduction
I've created a repo to reproduce the problem:
https://github.com/josecelano/sqlx-false-database-query-error
Info
0.6.3
["runtime-tokio-native-tls","sqlite","mysql","migrate","time",]
3.40.1 2022-12-28 14:03:47 df5c253c0b3dd24916e4ec7cf77d3db5294cc9fd45ae7b9c5e82ad8197f3alt1
Ubuntu 23.04
rustc --version
:rustc 1.71.0-nightly (18bfe5d8a 2023-05-14)
The sample repo output: