nodecosmos / charybdis

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

Empty set fails to deserialise back into empty hashset #33

Closed Zk2u closed 2 months ago

Zk2u commented 2 months ago

When a column with a Set type is inserted and defaulted (to become an empty hash set), it is stored in Scylla as null. When reading this, the crate fails to convert the null into an empty hashset.

Apologies for bad image

image

failed to find meals: NextRowError("SELECT chef, id, name, description, ingredients, allergens, dietary_requirements, images, added_on FROM meals WHERE chef = ?", FromRowError(BadCqlVal { err: ValIsNull, column: 7 }))
GoranBrkuljan commented 2 months ago

https://opensource.docs.scylladb.com/stable/cql/types.html#sets

ScyllaDB does not distinguish an empty collections from a missing value so using Option<Set<T>> is recommended.

Zk2u commented 2 months ago

That's so dumb, the main driver should use an empty collection for this case lol. Thank you, saved the day once again!

GoranBrkuljan commented 2 months ago

I agree, it's bit unexpected behavior. ~Maybe we could have some kind of compile time checks if collection is not Option and raise an error.~

Zk2u commented 2 months ago

Driver changes tracked upstream here.