Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Django RQ admin shows errors for circuit webhooks #2623

Closed
funzoneq opened this issue Nov 28, 2018 · 4 comments
Closed

Django RQ admin shows errors for circuit webhooks #2623

funzoneq opened this issue Nov 28, 2018 · 4 comments
Labels
status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application

Comments

@funzoneq
Copy link

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.
@jeremystretch jeremystretch added type: bug A confirmed report of unexpected behavior in the application status: accepted This issue has been accepted for implementation labels Nov 28, 2018
@jeremystretch
Copy link
Member

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
Copy link
Member

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

@jeremystretch jeremystretch added the status: blocked Another issue or external requirement is preventing implementation label Nov 28, 2018
@lampwins lampwins removed the status: blocked Another issue or external requirement is preventing implementation label Dec 4, 2018
@lampwins
Copy link
Contributor

lampwins commented 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.

@funzoneq
Copy link
Author

funzoneq commented Dec 5, 2018

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

@lock lock bot locked as resolved and limited conversation to collaborators Jan 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
Development

No branches or pull requests

3 participants