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

Replacements in collections use different serializer than insertions #917

Closed
kodemartin opened this issue Jul 21, 2023 · 0 comments
Closed
Assignees

Comments

@kodemartin
Copy link
Contributor

Versions/Environment

  1. What version of Rust are you using?
    cargo 1.68.2 (6feb7c9cf 2023-03-26)
    
  2. What operating system are you using?
    Linux 6.4.3-arch1-2 x86_64 GNU/Linux
    
  3. What versions of the driver and its dependencies are you using? (Run cargo pkgid mongodb & cargo pkgid bson)
    https://github.com/rust-lang/crates.io-index#[email protected]
    https://github.com/rust-lang/crates.io-index#[email protected]
    
  4. What version of MongoDB are you using? (Check with the MongoDB shell using db.version())
    6.0
    
  5. What is your MongoDB topology (standalone, replica set, sharded cluster, serverless)?
    replica set
    

Describe the bug

For types that use different a serializer for human-readable serialization, we face the following issue:

When inserted, values are serialized by the non-human readable serializer on account of using bson::to_vec under the hood.

However, if we try to replace such values all replace methods in Collection use internally bson::to_document that uses the human-readable serializer.

This implies that if we attempt to find such a value that has been replaced and deserialize, we will either get a deserialization error, or incorrect data.

To Reproduce
Steps to reproduce the behavior:

  1. Define a type that implements serde_with::SerializeAs using different serializers for human-readable (e.g. String) and non-readable (e.g. Bytes).
  2. Then insert a value of this type into a collection. Store it as original
  3. After doing that, replace that value with a clone of itself using any of the Collection methods that replace values (e.g. replace_one).
  4. Get the replaced value replaced from the database and verify that !assert_eq!(original, replaced).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants