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

Deserialization failure will swallow the query result #192

Open
ENJATZ opened this issue Dec 13, 2024 · 0 comments
Open

Deserialization failure will swallow the query result #192

ENJATZ opened this issue Dec 13, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@ENJATZ
Copy link

ENJATZ commented Dec 13, 2024

Describe the bug

Having a custom deserialization for one of the fields in the expected clickhouse::Row will swallow the returned rows if the deserialization is failing.

Steps to reproduce

  1. Have a struct with a field that has custom serialization/deserialization
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize, clickhouse::Row)]
pub struct Event {
    pub nonce: String,
    pub name: String,
    pub source_serial_number: Option<String>,
    pub source_device_id: ch::ChIdOption<model::pg::device::Id>,
}
  1. A simple query to to get the rows:
pub async fn get_by_id(
    client: &clickhouse::Client,
    id: &common_database::model::ch::event::Id,
) -> Result<Event, clickhouse::error::Error> {
    client
        .query("SELECT ?fields FROM event WHERE id = ?")
        .bind(id)
        .fetch_one::<Event>()
        .await
}

Expected behaviour

In this case, the targeted event, has a NULL value for source_device_id => which will fall under the case of clickhouse::serde::uuid::option::deserialize(deserializer) or even clickhouse::serde::uuid::deserialize(deserializer) (same result), in this case the uuid::deserialize should return None, but it it throwing an Err(NotEnoughData). Not handling the error, will just swallow the returned row.

Code example

ChIdOption deserialized with:

pub fn deserialize<'de, D, T>(deserializer: D) -> Result<Option<T>, D::Error>
            where
                D: serde::Deserializer<'de>,
                T: crate::DbId,
            {
                clickhouse::serde::uuid::option::deserialize(deserializer)
                    .map(|v| v.map(T::from_unsafe))
            }
@ENJATZ ENJATZ added the bug Something isn't working label Dec 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant