Django RQ admin shows errors for circuit webhooks #2154

Closed
opened 2025-12-29 17:22:44 +01:00 by adam · 4 comments
Owner

Originally created by @funzoneq on GitHub (Nov 28, 2018).

Environment

  • Python version: 3.6.4
  • NetBox version: 2.4.8

Steps to Reproduce

Create a webhook for circuits with the following settings:

Object type: Circuits -> Circuit
Name: test_circuit_hook
Type: Update
URL: https://example.com/webhook/
HTTP Content type: JSON
No secret
Enabled
SSL Verification enabled.
-> Save

Create a test circuit:

cid: test-001
Provider: test provider
Type: Internet
Status: Active
Tenant: Test tenant
Install_date, commit_rate, description, comments empty
No custom fields
Save the circuit.

No go back and edit the circuit. Change the cid to test-002. This will trigger the webhook. It doesn't matter if it fails or succeeds.

Go to the Django Admin -> Django RQ -> Queues -> Failed or Succeeded jobs list

Select a job for the circuit:

It throws a django error page:

<class 'django.db.models.fields.related_descriptors.RelatedObjectDoesNotExist'>

Circuit has no provider.

The object definitely has a provider assigned to it:

15:54:33 default: extras.webhooks_worker.process_webhook(<Webhook: test_hook_arnoud>, {'package': OrderedDict([('id', 10), ('url', '/api/tenancy/packages/10/'), ('name', 'L3-500m_500m'), ('slug', 'l3-500m_500m')]), 'install_date': None, 'created': '2018-11-27', 'custom_fields': {'script_time_circuit': None, 'EPLVlanId': None}, 'commit_rate': None, 'type': OrderedDict([('id', 3), ('url', '/api/circuits/circuit-types/3/'), ('name', 'Customer'), ('slug', 'customer')]), 'description': '', 'status': {'value': 3, 'label': 'Provisioning'}, 'tags': [], 'cid': 'test-circuit', 'provider': OrderedDict([('id', 12), ('url', '/api/circuits/providers/12/'), ('name', 'OpenFiber'), ('slug', 'openfiber')]), 'last_updated': '2018-11-28T15:54:33.037901Z', 'tenant': OrderedDict([('id', 1146), ('url', '/api/tenancy/tenants/1146/'), ('name', 'Race'), ('slug', 'race'), ('description', 'Race')]), 'id': 575, 'comments': ''}, <class 'circuits.models.Circuit'>, 2, '2018-11-28 15:54:33.098502') (942a9529-890e-4270-882d-6f3eca24e53e)

Expected Behavior

I expect to see a detail page for the (failed/succeeded) job

Observed Behavior

Django error page:

<class 'django.db.models.fields.related_descriptors.RelatedObjectDoesNotExist'>

Circuit has no provider.
Originally created by @funzoneq on GitHub (Nov 28, 2018). <!-- NOTE: This form is only for reproducible bugs. If you need assistance with NetBox installation, or if you have a general question, DO NOT open an issue. Instead, post to our mailing list: https://groups.google.com/forum/#!forum/netbox-discuss Please describe the environment in which you are running NetBox. Be sure that you are running an unmodified instance of the latest stable release before submitting a bug report. --> ### Environment * Python version: 3.6.4 * NetBox version: 2.4.8 <!-- Describe in detail the steps that someone else can take to reproduce this bug using the current stable release of NetBox (or the current beta release where applicable). --> ### Steps to Reproduce Create a webhook for circuits with the following settings: Object type: Circuits -> Circuit Name: test_circuit_hook Type: Update URL: https://example.com/webhook/ HTTP Content type: JSON No secret Enabled SSL Verification enabled. -> Save Create a test circuit: cid: test-001 Provider: test provider Type: Internet Status: Active Tenant: Test tenant Install_date, commit_rate, description, comments empty No custom fields Save the circuit. No go back and edit the circuit. Change the cid to test-002. This will trigger the webhook. It doesn't matter if it fails or succeeds. Go to the Django Admin -> Django RQ -> Queues -> Failed or Succeeded jobs list Select a job for the circuit: It throws a django error page: ``` <class 'django.db.models.fields.related_descriptors.RelatedObjectDoesNotExist'> Circuit has no provider. ``` The object definitely has a provider assigned to it: ``` 15:54:33 default: extras.webhooks_worker.process_webhook(<Webhook: test_hook_arnoud>, {'package': OrderedDict([('id', 10), ('url', '/api/tenancy/packages/10/'), ('name', 'L3-500m_500m'), ('slug', 'l3-500m_500m')]), 'install_date': None, 'created': '2018-11-27', 'custom_fields': {'script_time_circuit': None, 'EPLVlanId': None}, 'commit_rate': None, 'type': OrderedDict([('id', 3), ('url', '/api/circuits/circuit-types/3/'), ('name', 'Customer'), ('slug', 'customer')]), 'description': '', 'status': {'value': 3, 'label': 'Provisioning'}, 'tags': [], 'cid': 'test-circuit', 'provider': OrderedDict([('id', 12), ('url', '/api/circuits/providers/12/'), ('name', 'OpenFiber'), ('slug', 'openfiber')]), 'last_updated': '2018-11-28T15:54:33.037901Z', 'tenant': OrderedDict([('id', 1146), ('url', '/api/tenancy/tenants/1146/'), ('name', 'Race'), ('slug', 'race'), ('description', 'Race')]), 'id': 575, 'comments': ''}, <class 'circuits.models.Circuit'>, 2, '2018-11-28 15:54:33.098502') (942a9529-890e-4270-882d-6f3eca24e53e) ``` <!-- What did you expect to happen? --> ### Expected Behavior I expect to see a detail page for the (failed/succeeded) job <!-- What happened instead? --> ### Observed Behavior Django error page: ``` <class 'django.db.models.fields.related_descriptors.RelatedObjectDoesNotExist'> Circuit has no provider. ```
adam added the type: bugstatus: accepted labels 2025-12-29 17:22:44 +01:00
adam closed this issue 2025-12-29 17:22:44 +01:00
Author
Owner

@jeremystretch commented on GitHub (Nov 28, 2018):

This is happening because the webhook is passed only the model class (rather than an instance), but trying to access provider in rendering a string representation, yielding an exception:

class Circuit(ChangeLoggedModel, CustomFieldModel):
    ...
    def __str__(self):
        return '{} {}'.format(self.provider, self.cid)

The best approach is probably to tweak the __str__() method on this model (and others) to properly render when not instantiated.

@jeremystretch commented on GitHub (Nov 28, 2018): This is happening because the webhook is passed only the model class (rather than an instance), but trying to access `provider` in rendering a string representation, yielding an exception: ``` class Circuit(ChangeLoggedModel, CustomFieldModel): ... def __str__(self): return '{} {}'.format(self.provider, self.cid) ``` The best approach is probably to tweak the `__str__()` method on this model (and others) to properly render when not instantiated.
Author
Owner

@jeremystretch commented on GitHub (Nov 28, 2018):

To avoid confusion, I've opened #2627 to address the root cause of this bug. Marking this as blocked.

@jeremystretch commented on GitHub (Nov 28, 2018): To avoid confusion, I've opened #2627 to address the root cause of this bug. Marking this as blocked.
Author
Owner

@lampwins commented on GitHub (Dec 4, 2018):

While #2627 is a good idea, this specific issue was addressed by simply not passing the model class to the rqworker process. All we actually needed was the model_name attribute anyway, so we can just pass that as a string.

@lampwins commented on GitHub (Dec 4, 2018): While #2627 is a good idea, this specific issue was addressed by simply not passing the model class to the rqworker process. All we actually needed was the model_name attribute anyway, so we can just pass that as a string.
Author
Owner

@funzoneq commented on GitHub (Dec 5, 2018):

Thanks @lampwins and @jeremystretch . The help is much appreciated 👍

@funzoneq commented on GitHub (Dec 5, 2018): Thanks @lampwins and @jeremystretch . The help is much appreciated 👍
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#2154