ReferenceField with a Document with non-mongo-ObjectId.
jbkoh opened this issue · 3 comments
jbkoh commented
Hi again,
I have a Document whose ids are string. I would like to let another Document to Reference it like the following:
class AAA(Document):
id = StringFiled(attribute='_id')
class BBB(Document):
aaa = ReferenceField(AAA)
aaa_instance = AAA(id="abcd")
bbb_instance = BBB(aaa=aaa_instance.id)
However the last line gives me an error marshmallow.exceptions.ValidationError: Invalid ObjectId
.
I was actually expecting ReferenceField's field to receive the document instances asthe argument (i.e., BBB(aaa=aaa_instance)
), but umongo seems to interpret ReferenceField as ObjectIdField.
Is it an expected behavior or a bug? Thanks!
jbkoh commented
I just found
Line 319 in 96abcff
jbkoh commented
I looked through the code a bit and thought we could let Document to have other types than ObjectId as pk types. Maybe I'm wrong. Let me know if it's something worth investigating. Thanks!