javrasya / django-river

Django workflow library that supports on the fly changes ⛵
BSD 3-Clause "New" or "Revised" License
742 stars 105 forks source link

AttributeError: 'NoneType' object has no attribute '_meta' #46

Closed vladimirmyshkovski closed 5 years ago

vladimirmyshkovski commented 7 years ago

When I try add processing meta, I get error:

AttributeError: 'NoneType' object has no attribute '_meta'

and get 2 warnings:

WARNINGS: river.ProceedingMeta.groups: (fields.W340) null has no effect on ManyToManyField. river.ProceedingMeta.parents: (fields.W340) null has no effect on ManyToManyField.

Django version 1.11.1

vladimirmyshkovski commented 7 years ago

I found that the error in the river/admin/proceeding_meta.py

def get_content_types():
    content_type_pks = []
    ctt = ContentType.objects.all()
    for ct in ContentType.objects.all():
        model = ct.model_class() # <- HERE 
        for f in model._meta.fields:
            if type(f) is StateField:
                content_type_pks.append(ct.pk)
    return content_type_pks

When there is parsing the content_type, and it encounters an admin, he can not get his model_class ().

I have not figured out how to solve it correctly, but just adding :

        if not model:
            continue

Everything worked as expected

vladimirmyshkovski commented 7 years ago

Also, in Django 1.11.1 there is a command remove_stale_contenttypes, the implementation of which solves this problem

carlosmontoyamoya commented 6 years ago

Just you commented, it works fine.

def get_content_types():
    content_type_pks = []
    for ct in ContentType.objects.all():
        model = ct.model_class()
        if not model:
            continue
        for f in model._meta.fields:
            if type(f) is StateField:
                content_type_pks.append(ct.pk)

    return content_type_pks