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

replaceOneById doesn't use a custom CodecRegistry #389

Open
piglovesyou opened this issue Dec 24, 2022 · 3 comments
Open

replaceOneById doesn't use a custom CodecRegistry #389

piglovesyou opened this issue Dec 24, 2022 · 3 comments

Comments

@piglovesyou
Copy link

replaceOneById -> replaceOneWithoutId -> KMongoUtil.filterIdToBson -> SerializationClassMappingTypeService::filterIdToBson

I think in this line , it should access a custom codec registry that a user registered by MongoCollection::withCodecRegistry(registry). Because of this, it fails to find a codec and fails serialization.

@zigzago
Copy link
Member

zigzago commented Jan 10, 2023

Thank you for reporting. Could you provide a reproducible use case ? I infer it does not work for for a collection class that use a custom codec ? For which mapping engine ?

@piglovesyou
Copy link
Author

piglovesyou commented Jan 10, 2023

Thanks. Yes, when a collection with a custom codec registry calls .replaceOne() (or any method depending on KMongoUtil.filterIdToBson()), it ignores the registered codec registry; it uses a KMongo internal shared codec registry in SerializationClassMappingTypeService instead. Not sure about mapping engines, our project uses Kotlinx Serialization for serialization, but I don't think it affects the root cause.

@zigzago zigzago added the bug label Apr 3, 2023
@zigzago
Copy link
Member

zigzago commented Apr 11, 2023

Workaround: add the codec in MongoClientSettings.codecRegistry in KMongo.createClient(MongoClientSettings). Needs a major refactoring to fix the bug because the KMongoUtil.filterIdToBson() is stateless

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants