feat: UUID (and bson.Binary of UUID subtype) is accepted as a document _id field value#40
feat: UUID (and bson.Binary of UUID subtype) is accepted as a document _id field value#40Guibod wants to merge 1 commit intoscottrogowski:masterfrom
_id field value#40Conversation
_id field value_id field value
|
Thanks for the PR! Looks plausible. Will take a little while to review. I'm working on a SQLite implementation right now and luckily this looks like it would slide right in. |
|
@Guibod looks like this is failing unit tests
|
|
Thanks you @scottrogowski , i’ll try to check this as soon as possible. ❤️ |
|
Well, this issue was bound to the absence of for instance: mongoengine.connect('mongita_test_db')Was replaced by: mongoengine.connect('mongita_test_db', uuidRepresentation=UuidRepresentation.STANDARD)I hesitated at first to add a note in the You are all set and can review the PR once more ! |
|
And of course, i failed. I’ve only solved the warnings in my previous commit, and those warnings were bound to This is related to the fact that there was legacy implementation of the UUID in BSON between Java, Python and other. And that those legacy behaviors were unified under a new standard name. If you don’t specify your In my PR, i’ll need either to setup a default |
|
The solution is to enhance the My PR decide that mongita will only handle UUID using the new standard, and cannot be configured to any other value. It might be an issue for pre-existing database were the uuid was stored using legacy format (python), were they should change this codec option to |
As stated in #41 , anything can be used as an
_idin mongo, in this PR, i’ve lifted the validation limitations onbson.Binaryas a proper data type for_idtypes. This can then be used to storeUUIDvalues.UUIDandbson.Binarywith subtypes described inbson.binary.UuidRepresentationare two common ways of describing UUID in pymongo.UUIDis the python type andbson.Binaryis the storage type.I introduce a new method
mongita.engines.engine_common.Engine.hash_idthat transforms an eligible type to string. It replace thestr(doc_id)found in numerous places. It will support the transformation frombson.Binaryto string usingbson.binary.Binary.as_uuid.I’ve also needed to put a very specific comparison in
mongita.collection._doc_matches_slow_filtersin case of a user inputedbson.Binaryand a decoded binary bybson.decodethat is cast as a UUID.