Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DocumentAdmin: 'StringField' object has no attribute 'document_type' #4

Closed
audreyfeldroy opened this issue Dec 29, 2011 · 10 comments
Closed

Comments

@audreyfeldroy
Copy link

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).

@jschrewe
Copy link
Owner

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.

@justincy
Copy link

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

@jschrewe
Copy link
Owner

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.

@justincy
Copy link

What's the easiest way to view a the contents of a document? Printing just tells me what class it is.

@jschrewe
Copy link
Owner

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.

@justincy
Copy link

{'_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}

@jschrewe
Copy link
Owner

Thanks for the data. Sadly it helps little without the schema. My attempts at recreating the error have so far failed miserably.

@justincy
Copy link

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()

@justincy
Copy link

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?

@jschrewe
Copy link
Owner

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants