Closed audreyfeldroy closed 12 years ago
Could you post the document that produces the error? My guess is that there is an error in the first if
in get_inline_instances
.
I'm getting a similar error, except mine days "NoneType' object has no attribute 'document_type'". Perhaps bad data is causing this.
My fix was to change the if statement at line 346:
if hasattr(f, 'field') and f.field:
embedded_document = f.field.document_type
elif hasattr(f, 'document_type'):
embedded_document = f.document_type
else:
continue
Could you give me the definition of the document that causes this error? Because I don't see how and why an EmbeddedDocumentField
can be None. But it may well be I'm overlooking something here. And while your fix certainly works, I guess it could lead to missing InlineAdmins for some documents.
What's the easiest way to view a the contents of a document? Printing just tells me what class it is.
print obj.__dict__
prints out all the attributes of the object. Mongoengine keeps all the data in the obj.data
(or something similar) dict. None
is usually assigned to data that is defined on the document schema, but not stored in the database.
{'_data': {'motherID': None, 'families': [], 'tags': [], 'personal': None, 'fatherID': None, 'childrenIDs': [], 'missing': None, 'api_id': None, 'events': None, 'note': None, 'cached': False, 'api': None, 'relation': None, 'user': None, 'spouseID': None, 'synced': datetime.datetime(2012, 2, 15, 11, 47, 49, 316099), 'parents': [], 'ordinances': None, 'id': None}, '_initialised': True}
Thanks for the data. Sadly it helps little without the schema. My attempts at recreating the error have so far failed miserably.
class Person(Document):
user = ReferenceField('User',required=True)
# valid api values are "nfs"
api = StringField(max_length=50,required=True)
api_id = StringField(max_length=10,required=True)
cached = BooleanField(default=False)
synced = DateTimeField(default=datetime.datetime.now)
personal = EmbeddedDocumentField(Personal)
events = EmbeddedDocumentField(Events)
ordinances = EmbeddedDocumentField(Ordinances)
families = ListField(EmbeddedDocumentField(Family))
parents = ListField(EmbeddedDocumentField(Parents))
missing = EmbeddedDocumentField(Missing)
relation = StringField()
motherID = StringField(max_length=10)
fatherID = StringField(max_length=10)
# spouse and children should eventually be kept as part of a family
spouseID = StringField(max_length=10)
childrenIDs = ListField()
tags = ListField()
note = StringField()
I found more documents that cause the problem:
'NoneType' object has no attribute 'document_type'
{'admin_site': <mongoadmin.sites.AdminSite object at 0x2770c50>, 'model': <class 'family.models.Person'>, 'document': <class 'family.models.Person'>, 'inline_instances': [<mongoadmin.options.EmbeddedStackedDocumentAdmin object at 0x2e945d0>], 'opts': <mongodbforms.documentoptions.DocumentMetaWrapper object at 0x2e944d0>}
'NoneType' object has no attribute 'document_type'
{'admin_site': <mongoadmin.sites.AdminSite object at 0x2770c50>, 'model': <class 'family.models.Person'>, 'document': <class 'family.models.Person'>, 'inline_instances': [<mongoadmin.options.EmbeddedStackedDocumentAdmin object at 0x2e945d0>, <mongoadmin.options.EmbeddedStackedDocumentAdmin object at 0x2e947d0>], 'opts': <mongodbforms.documentoptions.DocumentMetaWrapper object at 0x2e944d0>}
Are these documents that the admin module uses?
@justincy Mongoadmin does not have any documents. Your data appears to be the admin object itself.
I've added your fix in the last commit, so that should close that.
I was getting the error "'StringField' object has no attribute 'document_type'"
Commenting out lines 341-361 of options.py resulted in getting the admin to work (although probably not the best thing to do, I'm guessing).