From 9738257aa289ccbf3952c9beddd239adac97e89c Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Wed, 7 Oct 2020 13:09:08 -0400 Subject: [PATCH] Fixes #5217: Prevent erroneous removal of prefetched GenericForeignKey data from tables --- docs/release-notes/version-2.9.md | 1 + netbox/utilities/tables.py | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/release-notes/version-2.9.md b/docs/release-notes/version-2.9.md index 06338cc65..bfe8ede46 100644 --- a/docs/release-notes/version-2.9.md +++ b/docs/release-notes/version-2.9.md @@ -12,6 +12,7 @@ * [#5199](https://github.com/netbox-community/netbox/issues/5199) - Change default LDAP logging to INFO * [#5201](https://github.com/netbox-community/netbox/issues/5201) - Fix missing querystring when bulk editing/deleting VLAN Group VLANs when selecting "select all x items matching query" * [#5206](https://github.com/netbox-community/netbox/issues/5206) - Apply user pagination preferences to all paginated object lists +* [#5217](https://github.com/netbox-community/netbox/issues/5217) - Prevent erroneous removal of prefetched GenericForeignKey data from tables --- diff --git a/netbox/utilities/tables.py b/netbox/utilities/tables.py index d1f17ff1e..9b0af61bc 100644 --- a/netbox/utilities/tables.py +++ b/netbox/utilities/tables.py @@ -1,4 +1,5 @@ import django_tables2 as tables +from django.contrib.contenttypes.fields import GenericForeignKey from django.core.exceptions import FieldDoesNotExist from django.db.models.fields.related import RelatedField from django.utils.safestring import mark_safe @@ -63,7 +64,7 @@ class BaseTable(tables.Table): field_path = column.accessor.split('.') try: model_field = model._meta.get_field(field_path[0]) - if isinstance(model_field, RelatedField): + if isinstance(model_field, (RelatedField, GenericForeignKey)): prefetch_fields.append('__'.join(field_path)) except FieldDoesNotExist: pass