List of Object Types in the Event Rule configuration is unreliable #10951

Closed
opened 2025-12-29 21:38:15 +01:00 by adam · 16 comments
Owner

Originally created by @peteeckel on GitHub (Mar 26, 2025).

Deployment Type

Self-hosted

NetBox Version

v4.2.6

Python Version

3.11

Steps to Reproduce

  1. Install two plugins, for example netbox-bgp and netbox-plugin-dns
  2. Enable the plugins in the configuration.py file, with netbox_dns first and netbox_bgp second:
PLUGINS = [
    'netbox_dns',
    'netbox_bgp',
]
  1. Run the migrations and restart NetBox
  2. Navigate to 'Operations'/'Event Rules'/'Add'
  3. Open the pulldown menu for 'Object Type'

Expected Behavior

Object types for NetBox DNS and NetBox BGP are selectable.

Observed Behavior

The models for the BGP plugin do not show up in the pulldown menu, the ones for DNS do:

Image Image
Originally created by @peteeckel on GitHub (Mar 26, 2025). ### Deployment Type Self-hosted ### NetBox Version v4.2.6 ### Python Version 3.11 ### Steps to Reproduce 1. Install two plugins, for example `netbox-bgp` and `netbox-plugin-dns` 2. Enable the plugins in the `configuration.py` file, with `netbox_dns` first and `netbox_bgp` second: ```python PLUGINS = [ 'netbox_dns', 'netbox_bgp', ] ``` 3. Run the migrations and restart NetBox 4. Navigate to 'Operations'/'Event Rules'/'Add' 5. Open the pulldown menu for 'Object Type' ### Expected Behavior Object types for NetBox DNS and NetBox BGP are selectable. ### Observed Behavior The models for the BGP plugin do not show up in the pulldown menu, the ones for DNS do: <img width="613" alt="Image" src="https://github.com/user-attachments/assets/f5e01eb9-d842-4f61-aca3-9c484a5392dc" /> <img width="619" alt="Image" src="https://github.com/user-attachments/assets/c20cefac-628d-423e-af84-f26fb8697605" />
adam added the type: bug label 2025-12-29 21:38:15 +01:00
adam closed this issue 2025-12-29 21:38:15 +01:00
Author
Owner

@peteeckel commented on GitHub (Mar 26, 2025):

Order of Plugins in the Configuration

If you configure the plugins in reverse order, BGP shows up as well:

PLUGINS = [
    'netbox_dns',
    'netbox_bgp',
]
Image

Verification of correct Registration

Regardless of which order is used, both plugins are registered with the event_rules feature:

(netbox) [root@dns netbox]# /opt/netbox/netbox/manage.py nbshell 
### NetBox interactive shell (dns.dev.hindenburgring.com)
### Python 3.11.5 | Django 5.1.7 | NetBox NetBox Community v4.2.6
### lsmodels() will show available models. Use help(<model>) for more info.
>>> from netbox.registry import registry
>>> registry["model_features"]["event_rules"]["netbox_dns"]
{'registrar', 'record', 'view', 'registrationcontact', 'zone', 'nameserver', 'recordtemplate', 'zonetemplate'}
>>> registry["model_features"]["event_rules"]["netbox_bgp"]
{'prefixlist', 'communitylistrule', 'bgppeergroup', 'communitylist', 'routingpolicyrule', 'community', 'prefixlistrule', 'bgpsession', 'routingpolicy'}

NetBox Version

I could reproduce this with all NetBox 4.2 releases, but not with 4.1.11, where independently of the order of plugins in the configuration the object classes appear in the event rule object type dropdown. This also means that this is probably not a duplicate of #18428.

IMHO it's extremely likely not an issue with one of the plugins, but with NetBox itself.

@peteeckel commented on GitHub (Mar 26, 2025): ## Order of Plugins in the Configuration If you configure the plugins in reverse order, BGP shows up as well: ```python PLUGINS = [ 'netbox_dns', 'netbox_bgp', ] ``` <img width="620" alt="Image" src="https://github.com/user-attachments/assets/ffa6ab48-279a-48c5-9810-0afc1b432572" /> ## Verification of correct Registration Regardless of which order is used, both plugins are registered with the `event_rules` feature: ``` (netbox) [root@dns netbox]# /opt/netbox/netbox/manage.py nbshell ### NetBox interactive shell (dns.dev.hindenburgring.com) ### Python 3.11.5 | Django 5.1.7 | NetBox NetBox Community v4.2.6 ### lsmodels() will show available models. Use help(<model>) for more info. >>> from netbox.registry import registry >>> registry["model_features"]["event_rules"]["netbox_dns"] {'registrar', 'record', 'view', 'registrationcontact', 'zone', 'nameserver', 'recordtemplate', 'zonetemplate'} >>> registry["model_features"]["event_rules"]["netbox_bgp"] {'prefixlist', 'communitylistrule', 'bgppeergroup', 'communitylist', 'routingpolicyrule', 'community', 'prefixlistrule', 'bgpsession', 'routingpolicy'} ``` ## NetBox Version I could reproduce this with all NetBox 4.2 releases, but not with 4.1.11, where independently of the order of plugins in the configuration the object classes appear in the event rule object type dropdown. This also means that this is probably not a duplicate of #18428. IMHO it's extremely likely not an issue with one of the plugins, but with NetBox itself.
Author
Owner

@peteeckel commented on GitHub (Mar 26, 2025):

I started investigating this because of the NetBox DNS issue https://github.com/peteeckel/netbox-plugin-dns/issues/582.

@peteeckel commented on GitHub (Mar 26, 2025): I started investigating this because of the NetBox DNS issue https://github.com/peteeckel/netbox-plugin-dns/issues/582.
Author
Owner

@arthanson commented on GitHub (Mar 26, 2025):

@peteeckel can you please re-check the steps as I'm not seeing this behavior, I'm on v4.2.6. The two screenshots are without any changes or reloads and I'm seeing both plugins listed

Image
Image

@arthanson commented on GitHub (Mar 26, 2025): @peteeckel can you please re-check the steps as I'm not seeing this behavior, I'm on v4.2.6. The two screenshots are without any changes or reloads and I'm seeing both plugins listed ![Image](https://github.com/user-attachments/assets/55db56c3-0b08-45a6-918a-4471b61e0c4e) ![Image](https://github.com/user-attachments/assets/49cabdcd-e048-47de-a046-27a8b9346015)
Author
Owner

@peteeckel commented on GitHub (Mar 26, 2025):

The steps are absolutely reproducible (I did it at least 10 times), but the behaviour itself may not be. If you look at the referenced NetBox DNS issue, the exact same thing happened but with the NetBox DNS objects appearing and disappearing depending on the order of configuration.

@peteeckel commented on GitHub (Mar 26, 2025): The steps are absolutely reproducible (I did it at least 10 times), but the behaviour itself may not be. If you look at the referenced NetBox DNS issue, the exact same thing happened but with the NetBox DNS objects appearing and disappearing depending on the order of configuration.
Author
Owner

@peteeckel commented on GitHub (Mar 26, 2025):

@arthanson did you try swapping the plugins in the configuration? Maybe it has something to do with which one was added to the database first.

And yes, I find this highly obscure as well.

@peteeckel commented on GitHub (Mar 26, 2025): @arthanson did you try swapping the plugins in the configuration? Maybe it has something to do with which one was added to the database first. And yes, I find this highly obscure as well.
Author
Owner

@peteeckel commented on GitHub (Mar 26, 2025):

It might even be the same thing @abhi1693 was seeing with 4.1.11 in #18428.

@peteeckel commented on GitHub (Mar 26, 2025): It might even be the same thing @abhi1693 was seeing with 4.1.11 in #18428.
Author
Owner

@peteeckel commented on GitHub (Mar 26, 2025):

I just made a new attempt with a completely fresh database. The rest just as described in the first comment. Versions are:

  • NetBox DNS 1.2.6
  • NetBox 4.2.6
  • NetBox BGP 0.15.0
  • RockyLinux 9.2
  • Python 3.11.5
  • PostgreSQL 15.5

NetBox DNS installed first, then NetBox BGP.

As above: DNS shows up in the object list, BGP doesn't.

The same behaviour is not observed in the object list for Permissions:

Image
@peteeckel commented on GitHub (Mar 26, 2025): I just made a new attempt with a completely fresh database. The rest just as described in the first comment. Versions are: * NetBox DNS 1.2.6 * NetBox 4.2.6 * NetBox BGP 0.15.0 * RockyLinux 9.2 * Python 3.11.5 * PostgreSQL 15.5 NetBox DNS installed first, then NetBox BGP. As above: DNS shows up in the object list, BGP doesn't. The same behaviour is **not** observed in the object list for Permissions: <img width="633" alt="Image" src="https://github.com/user-attachments/assets/8d14ac35-9c2e-433c-a8f0-0e4c3e9d4573" />
Author
Owner

@github-actions[bot] commented on GitHub (Apr 3, 2025):

This is a reminder that additional information is needed in order to further triage this issue. If the requested details are not provided, the issue will soon be closed automatically.

@github-actions[bot] commented on GitHub (Apr 3, 2025): This is a reminder that additional information is needed in order to further triage this issue. If the requested details are not provided, the issue will soon be closed automatically.
Author
Owner

@Chluz commented on GitHub (Apr 4, 2025):

Hi, am facing the exact same issue on a docker install.

NetBox Version: NetBox Community v4.2.6-Docker-3.2.0
Python Version: 3.12.3

I have rechecked the steps, and can do a video if needed to clarify the problem.
I think thats the only think that was being asked to be checked again ?

@Chluz commented on GitHub (Apr 4, 2025): Hi, am facing the exact same issue on a docker install. NetBox Version: NetBox Community v4.2.6-Docker-3.2.0 Python Version: 3.12.3 I have rechecked the steps, and can do a video if needed to clarify the problem. I think thats the only think that was being asked to be checked again ?
Author
Owner

@peteeckel commented on GitHub (Apr 8, 2025):

I found the time to investigate a bit deeper today.

First of all I patched EventRuleForm to get rid of the with_feature() method:

diff --git a/netbox/extras/forms/model_forms.py b/netbox/extras/forms/model_forms.py
index 299fff81b..272029d85 100644
--- a/netbox/extras/forms/model_forms.py
+++ b/netbox/extras/forms/model_forms.py
@@ -384,7 +384,7 @@ class WebhookForm(NetBoxModelForm):
 class EventRuleForm(NetBoxModelForm):
     object_types = ContentTypeMultipleChoiceField(
         label=_('Object types'),
-        queryset=ObjectType.objects.with_feature('event_rules'),
+        queryset=ObjectType.objects.all(),
     )
     event_types = forms.MultipleChoiceField(
         choices=get_event_type_choices(),

The result is, not very surprisingly, that the problem goes away. So the issue lies with the method in combination with the object_types field.

However, the filter method is apparently working correctly when I try it manually:

>>> ObjectType.objects.with_feature("event_rules").filter(app_label="netbox_bgp").values_list("model")
<QuerySet [('bgppeergroup',), ('bgpsession',), ('community',), ('communitylist',), ('communitylistrule',), ('prefixlist',), ('prefixlistrule',), ('routingpolicy',), ('routingpolicyrule',)]>

Which made me wonder why the with_feature("event_rules") condition does not work when the fields choices are initialised, but works perfectly later. And indeed: It's very likely a race condition, and that's why it's hard to reproduce.

I just applied two patches to the NetBox code:

diff --git a/netbox/utilities/forms/fields/content_types.py b/netbox/utilities/forms/fields/content_types.py
index 19da4c015..d5beccb61 100644
--- a/netbox/utilities/forms/fields/content_types.py
+++ b/netbox/utilities/forms/fields/content_types.py
@@ -2,6 +2,10 @@ from django import forms
 
 from utilities.object_types import object_type_name
 
+import logging
+logger = logging.getLogger("netbox_dns")
+
+
 __all__ = (
     'ContentTypeChoiceField',
     'ContentTypeMultipleChoiceField',
@@ -13,9 +17,12 @@ class ContentTypeChoiceMixin:
     def __init__(self, queryset, *args, **kwargs):
         # Order ContentTypes by app_label
         queryset = queryset.order_by('app_label', 'model')
+        if kwargs.get("label") == "Object types":
+            logger.debug("Initialising queryset for ContentType field 'Object types'")
         super().__init__(queryset, *args, **kwargs)
 
     def label_from_instance(self, obj):
+        logger.debug(f"label_from_instance: {obj}")
         try:
             return object_type_name(obj)
         except AttributeError:

and

diff --git a/netbox/netbox/models/features.py b/netbox/netbox/models/features.py
index a97227770..a8aa49af5 100644
--- a/netbox/netbox/models/features.py
+++ b/netbox/netbox/models/features.py
@@ -21,6 +21,9 @@ from utilities.json import CustomFieldJSONEncoder
 from utilities.serialization import serialize_object
 from utilities.views import register_model_view
 
+import logging
+logger = logging.getLogger("netbox_dns")
+
 __all__ = (
     'BookmarksMixin',
     'ChangeLoggingMixin',
@@ -619,6 +622,8 @@ def register_models(*models):
     """
     for model in models:
         app_label, model_name = model._meta.label_lower.split('.')
+        if app_label == "netbox_bgp":
+            logger.debug(f"Registering features for model {app_label}.{model_name}")
 
         # Register public models
         if not getattr(model, '_netbox_private', False):

This adds simple log messages in two places: When the queryset for the ContentTypeMultipleChoiceField in the EventRuleForm is initialised (this happens at NetBox startup) and when the features for the NetBox BGP models are registered.

When I now restart NetBox, I get the following output in the log:

Initialising queryset for ContentType field 'Object types'
Initialising queryset for ContentType field 'Object types'
Initialising queryset for ContentType field 'Object types'
Initialising queryset for ContentType field 'Object types'
Initialising queryset for ContentType field 'Object types'
Initialising queryset for ContentType field 'Object types'
Initialising queryset for ContentType field 'Object types'
Initialising queryset for ContentType field 'Object types'
Registering features for model netbox_bgp.routingpolicy
Registering features for model netbox_bgp.bgppeergroup
Registering features for model netbox_bgp.community
Registering features for model netbox_bgp.communitylist
Registering features for model netbox_bgp.communitylistrule
Registering features for model netbox_bgp.prefixlist
Registering features for model netbox_bgp.prefixlistrule
Registering features for model netbox_bgp.bgpsession
Registering features for model netbox_bgp.routingpolicyrule
Initialising queryset for ContentType field 'Object types'
Initialising queryset for ContentType field 'Object types'
Initialising queryset for ContentType field 'Object types'
Initialising queryset for ContentType field 'Object types'
Initialising queryset for ContentType field 'Object types'
Initialising queryset for ContentType field 'Object types'
Initialising queryset for ContentType field 'Object types'
Initialising queryset for ContentType field 'Object types'
Registering features for model netbox_bgp.routingpolicy
Registering features for model netbox_bgp.bgppeergroup
Registering features for model netbox_bgp.community
Registering features for model netbox_bgp.communitylist
Registering features for model netbox_bgp.communitylistrule
Registering features for model netbox_bgp.prefixlist
Registering features for model netbox_bgp.prefixlistrule
Registering features for model netbox_bgp.bgpsession
Registering features for model netbox_bgp.routingpolicyrule
Initialising queryset for ContentType field 'Object types'
Initialising queryset for ContentType field 'Object types'
Initialising queryset for ContentType field 'Object types'
Initialising queryset for ContentType field 'Object types'
Initialising queryset for ContentType field 'Object types'
Initialising queryset for ContentType field 'Object types'
Initialising queryset for ContentType field 'Object types'
Initialising queryset for ContentType field 'Object types'
Initialising queryset for ContentType field 'Object types'
Initialising queryset for ContentType field 'Object types'
Initialising queryset for ContentType field 'Object types'
Initialising queryset for ContentType field 'Object types'
Initialising queryset for ContentType field 'Object types'
Initialising queryset for ContentType field 'Object types'
Initialising queryset for ContentType field 'Object types'
Initialising queryset for ContentType field 'Object types'
Registering features for model netbox_bgp.routingpolicy
Registering features for model netbox_bgp.bgppeergroup
Registering features for model netbox_bgp.community
Registering features for model netbox_bgp.communitylist
Registering features for model netbox_bgp.communitylistrule
Registering features for model netbox_bgp.prefixlist
Registering features for model netbox_bgp.prefixlistrule
Registering features for model netbox_bgp.bgpsession
Registering features for model netbox_bgp.routingpolicyrule
Registering features for model netbox_bgp.routingpolicy
Registering features for model netbox_bgp.bgppeergroup
Registering features for model netbox_bgp.community
Registering features for model netbox_bgp.communitylist
Registering features for model netbox_bgp.communitylistrule
Registering features for model netbox_bgp.prefixlist
Registering features for model netbox_bgp.prefixlistrule
Registering features for model netbox_bgp.bgpsession
Registering features for model netbox_bgp.routingpolicyrule
Initialising queryset for ContentType field 'Object types'
Initialising queryset for ContentType field 'Object types'
Initialising queryset for ContentType field 'Object types'
Initialising queryset for ContentType field 'Object types'
Initialising queryset for ContentType field 'Object types'
Initialising queryset for ContentType field 'Object types'
Initialising queryset for ContentType field 'Object types'
Initialising queryset for ContentType field 'Object types'
Initialising queryset for ContentType field 'Object types'
Registering features for model netbox_bgp.routingpolicy
Registering features for model netbox_bgp.bgppeergroup
Registering features for model netbox_bgp.community
Registering features for model netbox_bgp.communitylist
Registering features for model netbox_bgp.communitylistrule
Registering features for model netbox_bgp.prefixlist
Registering features for model netbox_bgp.prefixlistrule
Registering features for model netbox_bgp.bgpsession
Registering features for model netbox_bgp.routingpolicyrule
Initialising queryset for ContentType field 'Object types'
Initialising queryset for ContentType field 'Object types'
Initialising queryset for ContentType field 'Object types'
Initialising queryset for ContentType field 'Object types'
Initialising queryset for ContentType field 'Object types'
Initialising queryset for ContentType field 'Object types'
Initialising queryset for ContentType field 'Object types'
Initialising queryset for ContentType field 'Object types'
Registering features for model netbox_bgp.routingpolicy
Registering features for model netbox_bgp.bgppeergroup
Registering features for model netbox_bgp.community
Registering features for model netbox_bgp.communitylist
Registering features for model netbox_bgp.communitylistrule
Registering features for model netbox_bgp.prefixlist
Registering features for model netbox_bgp.prefixlistrule
Registering features for model netbox_bgp.bgpsession
Registering features for model netbox_bgp.routingpolicyrule

Apparently in many cases the queryset for the field is initialised before the features for the model are registered, so the with_feature("event_rules") filter will not return the object types for the plugin when the field is initialised, although it does work later on.

@peteeckel commented on GitHub (Apr 8, 2025): I found the time to investigate a bit deeper today. First of all I patched `EventRuleForm` to get rid of the `with_feature()` method: ``` diff --git a/netbox/extras/forms/model_forms.py b/netbox/extras/forms/model_forms.py index 299fff81b..272029d85 100644 --- a/netbox/extras/forms/model_forms.py +++ b/netbox/extras/forms/model_forms.py @@ -384,7 +384,7 @@ class WebhookForm(NetBoxModelForm): class EventRuleForm(NetBoxModelForm): object_types = ContentTypeMultipleChoiceField( label=_('Object types'), - queryset=ObjectType.objects.with_feature('event_rules'), + queryset=ObjectType.objects.all(), ) event_types = forms.MultipleChoiceField( choices=get_event_type_choices(), ``` The result is, not very surprisingly, that the problem goes away. So the issue lies with the method in combination with the `object_types` field. However, the filter method is apparently working correctly when I try it manually: ```python >>> ObjectType.objects.with_feature("event_rules").filter(app_label="netbox_bgp").values_list("model") <QuerySet [('bgppeergroup',), ('bgpsession',), ('community',), ('communitylist',), ('communitylistrule',), ('prefixlist',), ('prefixlistrule',), ('routingpolicy',), ('routingpolicyrule',)]> ``` Which made me wonder why the `with_feature("event_rules")` condition does not work when the fields choices are initialised, but works perfectly later. And indeed: It's very likely a race condition, and that's why it's hard to reproduce. I just applied two patches to the NetBox code: ```python diff --git a/netbox/utilities/forms/fields/content_types.py b/netbox/utilities/forms/fields/content_types.py index 19da4c015..d5beccb61 100644 --- a/netbox/utilities/forms/fields/content_types.py +++ b/netbox/utilities/forms/fields/content_types.py @@ -2,6 +2,10 @@ from django import forms from utilities.object_types import object_type_name +import logging +logger = logging.getLogger("netbox_dns") + + __all__ = ( 'ContentTypeChoiceField', 'ContentTypeMultipleChoiceField', @@ -13,9 +17,12 @@ class ContentTypeChoiceMixin: def __init__(self, queryset, *args, **kwargs): # Order ContentTypes by app_label queryset = queryset.order_by('app_label', 'model') + if kwargs.get("label") == "Object types": + logger.debug("Initialising queryset for ContentType field 'Object types'") super().__init__(queryset, *args, **kwargs) def label_from_instance(self, obj): + logger.debug(f"label_from_instance: {obj}") try: return object_type_name(obj) except AttributeError: ``` and ```python diff --git a/netbox/netbox/models/features.py b/netbox/netbox/models/features.py index a97227770..a8aa49af5 100644 --- a/netbox/netbox/models/features.py +++ b/netbox/netbox/models/features.py @@ -21,6 +21,9 @@ from utilities.json import CustomFieldJSONEncoder from utilities.serialization import serialize_object from utilities.views import register_model_view +import logging +logger = logging.getLogger("netbox_dns") + __all__ = ( 'BookmarksMixin', 'ChangeLoggingMixin', @@ -619,6 +622,8 @@ def register_models(*models): """ for model in models: app_label, model_name = model._meta.label_lower.split('.') + if app_label == "netbox_bgp": + logger.debug(f"Registering features for model {app_label}.{model_name}") # Register public models if not getattr(model, '_netbox_private', False): ``` This adds simple log messages in two places: When the queryset for the `ContentTypeMultipleChoiceField` in the `EventRuleForm` is initialised (this happens at NetBox startup) and when the features for the NetBox BGP models are registered. When I now restart NetBox, I get the following output in the log: ``` Initialising queryset for ContentType field 'Object types' Initialising queryset for ContentType field 'Object types' Initialising queryset for ContentType field 'Object types' Initialising queryset for ContentType field 'Object types' Initialising queryset for ContentType field 'Object types' Initialising queryset for ContentType field 'Object types' Initialising queryset for ContentType field 'Object types' Initialising queryset for ContentType field 'Object types' Registering features for model netbox_bgp.routingpolicy Registering features for model netbox_bgp.bgppeergroup Registering features for model netbox_bgp.community Registering features for model netbox_bgp.communitylist Registering features for model netbox_bgp.communitylistrule Registering features for model netbox_bgp.prefixlist Registering features for model netbox_bgp.prefixlistrule Registering features for model netbox_bgp.bgpsession Registering features for model netbox_bgp.routingpolicyrule Initialising queryset for ContentType field 'Object types' Initialising queryset for ContentType field 'Object types' Initialising queryset for ContentType field 'Object types' Initialising queryset for ContentType field 'Object types' Initialising queryset for ContentType field 'Object types' Initialising queryset for ContentType field 'Object types' Initialising queryset for ContentType field 'Object types' Initialising queryset for ContentType field 'Object types' Registering features for model netbox_bgp.routingpolicy Registering features for model netbox_bgp.bgppeergroup Registering features for model netbox_bgp.community Registering features for model netbox_bgp.communitylist Registering features for model netbox_bgp.communitylistrule Registering features for model netbox_bgp.prefixlist Registering features for model netbox_bgp.prefixlistrule Registering features for model netbox_bgp.bgpsession Registering features for model netbox_bgp.routingpolicyrule Initialising queryset for ContentType field 'Object types' Initialising queryset for ContentType field 'Object types' Initialising queryset for ContentType field 'Object types' Initialising queryset for ContentType field 'Object types' Initialising queryset for ContentType field 'Object types' Initialising queryset for ContentType field 'Object types' Initialising queryset for ContentType field 'Object types' Initialising queryset for ContentType field 'Object types' Initialising queryset for ContentType field 'Object types' Initialising queryset for ContentType field 'Object types' Initialising queryset for ContentType field 'Object types' Initialising queryset for ContentType field 'Object types' Initialising queryset for ContentType field 'Object types' Initialising queryset for ContentType field 'Object types' Initialising queryset for ContentType field 'Object types' Initialising queryset for ContentType field 'Object types' Registering features for model netbox_bgp.routingpolicy Registering features for model netbox_bgp.bgppeergroup Registering features for model netbox_bgp.community Registering features for model netbox_bgp.communitylist Registering features for model netbox_bgp.communitylistrule Registering features for model netbox_bgp.prefixlist Registering features for model netbox_bgp.prefixlistrule Registering features for model netbox_bgp.bgpsession Registering features for model netbox_bgp.routingpolicyrule Registering features for model netbox_bgp.routingpolicy Registering features for model netbox_bgp.bgppeergroup Registering features for model netbox_bgp.community Registering features for model netbox_bgp.communitylist Registering features for model netbox_bgp.communitylistrule Registering features for model netbox_bgp.prefixlist Registering features for model netbox_bgp.prefixlistrule Registering features for model netbox_bgp.bgpsession Registering features for model netbox_bgp.routingpolicyrule Initialising queryset for ContentType field 'Object types' Initialising queryset for ContentType field 'Object types' Initialising queryset for ContentType field 'Object types' Initialising queryset for ContentType field 'Object types' Initialising queryset for ContentType field 'Object types' Initialising queryset for ContentType field 'Object types' Initialising queryset for ContentType field 'Object types' Initialising queryset for ContentType field 'Object types' Initialising queryset for ContentType field 'Object types' Registering features for model netbox_bgp.routingpolicy Registering features for model netbox_bgp.bgppeergroup Registering features for model netbox_bgp.community Registering features for model netbox_bgp.communitylist Registering features for model netbox_bgp.communitylistrule Registering features for model netbox_bgp.prefixlist Registering features for model netbox_bgp.prefixlistrule Registering features for model netbox_bgp.bgpsession Registering features for model netbox_bgp.routingpolicyrule Initialising queryset for ContentType field 'Object types' Initialising queryset for ContentType field 'Object types' Initialising queryset for ContentType field 'Object types' Initialising queryset for ContentType field 'Object types' Initialising queryset for ContentType field 'Object types' Initialising queryset for ContentType field 'Object types' Initialising queryset for ContentType field 'Object types' Initialising queryset for ContentType field 'Object types' Registering features for model netbox_bgp.routingpolicy Registering features for model netbox_bgp.bgppeergroup Registering features for model netbox_bgp.community Registering features for model netbox_bgp.communitylist Registering features for model netbox_bgp.communitylistrule Registering features for model netbox_bgp.prefixlist Registering features for model netbox_bgp.prefixlistrule Registering features for model netbox_bgp.bgpsession Registering features for model netbox_bgp.routingpolicyrule ``` Apparently in many cases the queryset for the field is initialised **before** the features for the model are registered, so the `with_feature("event_rules")` filter will **not** return the object types for the plugin when the field is initialised, although it **does** work later on.
Author
Owner

@peteeckel commented on GitHub (Apr 8, 2025):

It seems there is something in NetBox DNS causing this behaviour, but currently I still don't see what it is. There are two things I noticed:

  1. Whether or not this race condition occurs seems to depend on whether NetBox DNS is loaded first or last. If I put netbox_dns at the last position in the PLUGINS list, all the Initialising queryset ... messages occur at the end, after all Registering features messages are through.

  2. If NetBox DNS is installed and enabled, there are a lot more of the Initialising queryset ... messages. So apparently something is causing the forms that contain the ContentTypeMultipleChoiceField instances to be loaded multiple times. They are, however, not used in NetBox DNS at all ... to be precise, there are 9 of them when NetBox DNS is not loaded and 49 if it is, so loading NetBox DNS seems to cause 40 extra initialisations of the field.

  3. From the log it seems that the instantiation occurs in 5 blocks of 8 fields, while the normal instantiation is 1 block with 9 fields. Whatever that means.

So the question seems to be: What causes ContentTypeMultipleChoiceField and ContentTypeChoiceField objects to be instantiated?

@peteeckel commented on GitHub (Apr 8, 2025): It seems there is something in NetBox DNS causing this behaviour, but currently I still don't see what it is. There are two things I noticed: 1. Whether or not this race condition occurs seems to depend on whether NetBox DNS is loaded first or last. If I put `netbox_dns` at the last position in the `PLUGINS` list, all the `Initialising queryset ...` messages occur at the end, after all `Registering features` messages are through. 2. If NetBox DNS is installed and enabled, there are a lot more of the `Initialising queryset ...` messages. So apparently something is causing the forms that contain the `ContentTypeMultipleChoiceField` instances to be loaded multiple times. They are, however, not used in NetBox DNS at all ... to be precise, there are 9 of them when NetBox DNS is not loaded and 49 if it is, so loading NetBox DNS seems to cause 40 extra initialisations of the field. 3. From the log it seems that the instantiation occurs in 5 blocks of 8 fields, while the normal instantiation is 1 block with 9 fields. Whatever **that** means. So the question seems to be: What causes `ContentTypeMultipleChoiceField` and `ContentTypeChoiceField` objects to be instantiated?
Author
Owner

@peteeckel commented on GitHub (Apr 8, 2025):

Additional information: I can get almost the same behaviour without using NetBox DNS.

NetBox Secrets behaves almost the same, except that putting it last in the list doesn't help. And with NetBox Secrets, exactly like NetBox DNS, there are 40 additional instantiations of the "Object types" field.

Versions exactly like above, NetBox Secrets is at the latest release (2.2.0).

@peteeckel commented on GitHub (Apr 8, 2025): Additional information: I can get almost the same behaviour without using NetBox DNS. NetBox Secrets behaves almost the same, except that putting it last in the list doesn't help. And with NetBox Secrets, exactly like NetBox DNS, there are 40 additional instantiations of the "Object types" field. Versions exactly like above, NetBox Secrets is at the latest release (2.2.0).
Author
Owner

@kkthxbye-code commented on GitHub (Apr 9, 2025):

So the question seems to be: What causes ContentTypeMultipleChoiceField and ContentTypeChoiceField objects to be instantiated?

They are instantiated on load. I looked at the traceback for you. The following import in netbox-plugin-dns ultimately causes the EventRuleForm to be loaded.

be801463e9/netbox_dns/init.py#L106

Image

@kkthxbye-code commented on GitHub (Apr 9, 2025): > So the question seems to be: What causes `ContentTypeMultipleChoiceField` and `ContentTypeChoiceField` objects to be instantiated? They are instantiated on load. I looked at the traceback for you. The following import in netbox-plugin-dns ultimately causes the EventRuleForm to be loaded. https://github.com/peteeckel/netbox-plugin-dns/blob/be801463e954efab890cd1cd503f72364ed948a5/netbox_dns/__init__.py#L106 ![Image](https://github.com/user-attachments/assets/d5b30514-8711-4469-9ad2-0d1a4bfa99a6)
Author
Owner

@peteeckel commented on GitHub (Apr 9, 2025):

Hi @kkthxbye-code, thanks. That was the missing piece.

I just removed the workaround from ready() and added it to urls.py, and now the problem is solved for NetBox DNS at least. Will look at NetBox Secrets later on, as I suspect that there's a similar situation.

@peteeckel commented on GitHub (Apr 9, 2025): Hi @kkthxbye-code, **thanks**. That was the missing piece. I just removed the workaround from `ready()` and added it to `urls.py`, and now the problem is solved for NetBox DNS at least. Will look at NetBox Secrets later on, as I suspect that there's a similar situation.
Author
Owner

@github-actions[bot] commented on GitHub (Apr 22, 2025):

This is a reminder that additional information is needed in order to further triage this issue. If the requested details are not provided, the issue will soon be closed automatically.

@github-actions[bot] commented on GitHub (Apr 22, 2025): This is a reminder that additional information is needed in order to further triage this issue. If the requested details are not provided, the issue will soon be closed automatically.
Author
Owner

@jeremystretch commented on GitHub (Apr 22, 2025):

Closing this out as it appears to have been resolved.

@jeremystretch commented on GitHub (Apr 22, 2025): Closing this out as it appears to have been resolved.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#10951