Open
Description
Hi all,
I have encountered a problem dereferencing instances when that have a primary key that is a UUID that is stored in mongodb as a string.
class Pool(db.Document):
uuid = db.UUIDField(required=True, primary_key=True, binary=False)
class Host(db.Document):
uuid = db.UUIDField(required=True, primary_key=True, binary=False )
pool = db.ReferenceField(Pool)
When I try to access to pool attribute I get a DBRef instance instead a Pool instance.
p = Pool(uuid="36a36f7b-54b7-724f-d28d-2262a629c18a")
h = Host(uuid="70a36f7b-1db7-724f-d28d-2262a629c36b")
h.pool = p
h.save()
host = Host.objects.get(uuid="70a36f7b-1db7-724f-d28d-2262a629c36b")
host.pool
DBRef('pool', UUID('36a36f7b-54b7-724f-d28d-2262a629c18a'))
The DBRef contains the UUID object but the value is stored as string in mongodb. So when this is used in the get of ReferenceField class the search is done using the UUID object instead of the string:
if self._auto_dereference and isinstance(value, DBRef):
value = self.document_type._get_db().dereference(value)
end return None
If the uuid is stored using binary=True all works fine.