From 54d8c64ad5c643c1a3acda82e1b9f6da22e73146 Mon Sep 17 00:00:00 2001 From: Freyr Date: Thu, 25 May 2017 10:44:29 -0400 Subject: [PATCH] Fixes query operations on BinaryFields Overrides prepare_query_value in BinaryField to wrap the query value in bson.binary.Binary. This was already done in the to_mongo call when saving a document, but query operations required the user to convert the value manually. Fixes https://github.com/MongoEngine/mongoengine/issues/1127 --- mongoengine/fields.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mongoengine/fields.py b/mongoengine/fields.py index 0d402712..c52c6786 100644 --- a/mongoengine/fields.py +++ b/mongoengine/fields.py @@ -1393,6 +1393,12 @@ class BinaryField(BaseField): if self.max_bytes is not None and len(value) > self.max_bytes: self.error('Binary value is too long') + def prepare_query_value(self, op, value): + if value is None: + return value + return super(BinaryField, self).prepare_query_value( + op, self.to_mongo(value)) + class GridFSError(Exception): pass