Просмотр исходного кода

Fixes #5217: Prevent erroneous removal of prefetched GenericForeignKey data from tables

Jeremy Stretch 5 лет назад
Родитель
Сommit
9738257aa2
2 измененных файлов с 3 добавлено и 1 удалено
  1. 1 0
      docs/release-notes/version-2.9.md
  2. 2 1
      netbox/utilities/tables.py

+ 1 - 0
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
 
 ---
 

+ 2 - 1
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