wagtail / wagtail.org

Wagtail’s official marketing website
https://wagtail.org/
66 stars 60 forks source link

500 error for object references usage count #339

Closed thibaudcolas closed 1 year ago

thibaudcolas commented 1 year ago

Tested while trying to access the "Usage" page for any image or document. The error seems to be the same in both cases. Usage counts for snippets seem to work as expected.

Error:

AttributeError /admin/documents/usage/{document_id}/
'GenericForeignKey' object has no attribute 'verbose_name'

Code (exception raised on last line) wagtail/models/reference_index.py in describe_source_field at line 491:

        # ManyToOneRel (reverse accessor for ParentalKey) does not have a verbose name. So get the name of the child field instead
        if isinstance(field, models.ManyToOneRel):
            child_field = field.related_model._meta.get_field(model_path_components[2])
            return capfirst(child_field.verbose_name)
        else:
            return capfirst(field.verbose_name)

Sentry issue (public link): https://sentry.io/share/issue/bc084fb45cf34d74ae938ed532c5e851/

zerolab commented 1 year ago

Fixed in Wagtail 4.1.1 (https://github.com/wagtail/wagtail/pull/9631 specifically)