nodecosmos / charybdis

Rust ORM for ScyllaDB and Apache Cassandra
MIT License
108 stars 6 forks source link

Failed to type check Rust type uuid::Uuid against CQL type Timeuuid: expected one of the CQL types: [Uuid] #26

Closed hadronzoo closed 2 months ago

hadronzoo commented 2 months ago

This test fails with the following error:

called `Result::unwrap()` on an `Err` value: QueryError("INSERT INTO test (id) VALUES (:id)", BadQuery(SerializationError(SerializationError(BuiltinSerializationError { rust_name: "test::Test", kind: ColumnSerializationFailed { name: "id", err: SerializationError(BuiltinTypeCheckError { rust_name: "uuid::Uuid", got: Timeuuid, kind: MismatchedType { expected: [Uuid] } }) } }))))
#[cfg(test)]
mod test {
    use charybdis::operations::Insert;
    use charybdis::types::{Timeuuid, Uuid};
    use charybdis_macros::charybdis_model;
    use scylla::{CachingSession, SessionBuilder};
    use std::str::FromStr;

    #[derive(Debug, Default)]
    #[charybdis_model(
        table_name = test,
        partition_keys = [id],
        clustering_keys = [],
    )]
    struct Test {
        id: Timeuuid,
    }

    #[tokio::test]
    async fn test() {
        let session = SessionBuilder::new()
            .known_node("localhost")
            .use_keyspace("test", true)
            .build()
            .await
            .unwrap();

        let session = CachingSession::from(session, 100);
        let record = Test {
            id: Uuid::from_str("b01e22a8-0205-11ef-8f3a-42048a2ee1aa").unwrap(),
        };

        record.insert().execute(&session).await.unwrap();
    }
}
GoranBrkuljan commented 2 months ago

It looks like current driver versions uses newtype

pub struct CqlTimeuuid(Uuid)

Now in our ORM we want our types to support serde, so we need to create our own wrapper and implement required traits.

pub struct Timeuuid(CqlTimeuuid);

We did same thing for Counter & Duration types. I'll try to fix it tomorrow. I see that you are writing tests, in our main platform we don't use Timeuuid in our models, so it's not caught. If you are interested, help would be welcomed. ATM I am super busy on finalizing our main platform, so I didn't have time to setup CI/CD here.

GoranBrkuljan commented 2 months ago

fixed in v0.5.1