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

Exception trying to define an event rule with a custom script #15855

Closed
peteeckel opened this issue Apr 25, 2024 · 0 comments
Closed

Exception trying to define an event rule with a custom script #15855

peteeckel opened this issue Apr 25, 2024 · 0 comments
Assignees
Labels
beta Concerns a bug/feature in a beta release severity: medium Results in substantial degraded or broken functionality for specfic workflows status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application

Comments

@peteeckel
Copy link
Contributor

Deployment Type

Self-hosted

NetBox Version

4.0.0-beta2

Python Version

3.11

Steps to Reproduce

  1. Create a test custom script
from extras.scripts import Script

class Test(Script):
    class Meta:
        name = "Test Script"

    def run(self, data, commit):
        self.log_info("Test script executed")
  1. Upload the script to the NetBox server
  2. Run the script manually to verify that it's working
Screenshot 2024-04-25 at 20 37 48 4. Now create a new Event Rule for any object type, set the action type to 'Script' and select the test script created above

Expected Behavior

An event rule is created

Observed Behavior

Traceback (most recent call last):
  File "/opt/netbox/lib64/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
               ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/lib64/python3.11/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/lib64/python3.11/site-packages/django/views/generic/base.py", line 104, in view
    return self.dispatch(request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/netbox/netbox/views/generic/object_views.py", line 175, in dispatch
    return super().dispatch(request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/netbox/netbox/views/generic/base.py", line 26, in dispatch
    return super().dispatch(request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/netbox/utilities/views.py", line 108, in dispatch
    return super().dispatch(request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/lib64/python3.11/site-packages/django/views/generic/base.py", line 143, in dispatch
    return handler(request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/netbox/netbox/views/generic/object_views.py", line 269, in post
    obj = form.save()
          ^^^^^^^^^^^
  File "/opt/netbox/lib64/python3.11/site-packages/django/forms/models.py", line 552, in save
    self.instance.save()
    ^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/lib64/python3.11/site-packages/django/db/models/base.py", line 822, in save
    self.save_base(
    ^
  File "/opt/netbox/lib64/python3.11/site-packages/django/db/models/base.py", line 924, in save_base
    post_save.send(
    ^
  File "/opt/netbox/lib64/python3.11/site-packages/django/dispatch/dispatcher.py", line 189, in send
    response = receiver(signal=self, sender=sender, **named)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/netbox/extras/signals.py", line 122, in handle_changed_object
    enqueue_object(queue, instance, request.user, request.id, action)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/netbox/extras/events.py", line 65, in enqueue_object
    'data': serialize_for_event(instance),
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/netbox/extras/events.py", line 32, in serialize_for_event
    return serializer.data
           ^^^^^^^^^^^^^^^
  File "/opt/netbox/lib64/python3.11/site-packages/rest_framework/serializers.py", line 571, in data
    ret = super().data
          ^^^^^^^^^^^^
  File "/opt/netbox/lib64/python3.11/site-packages/rest_framework/serializers.py", line 249, in data
    self._data = self.to_representation(self.instance)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/lib64/python3.11/site-packages/rest_framework/serializers.py", line 538, in to_representation
    ret[field.field_name] = field.to_representation(attribute)
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/lib64/python3.11/site-packages/rest_framework/fields.py", line 1872, in to_representation
    return method(value)
           ^^^^^^^^^^^^^
  File "/opt/netbox/netbox/extras/api/serializers_/events.py", line 51, in get_action_object
    return ScriptSerializer(instance, nested=True, context=context).data
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/lib64/python3.11/site-packages/rest_framework/serializers.py", line 571, in data
    ret = super().data
          ^^^^^^^^^^^^
  File "/opt/netbox/lib64/python3.11/site-packages/rest_framework/serializers.py", line 249, in data
    self._data = self.to_representation(self.instance)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/lib64/python3.11/site-packages/rest_framework/serializers.py", line 538, in to_representation
    ret[field.field_name] = field.to_representation(attribute)
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/lib64/python3.11/site-packages/rest_framework/relations.py", line 396, in to_representation
    url = self.get_url(value, self.view_name, request, format)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/lib64/python3.11/site-packages/rest_framework/relations.py", line 332, in get_url
    lookup_value = getattr(obj, self.lookup_field)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Exception Type: AttributeError at /extras/event-rules/add/
Exception Value: 'Test' object has no attribute 'pk'
@peteeckel peteeckel added status: needs triage This issue is awaiting triage by a maintainer type: bug A confirmed report of unexpected behavior in the application labels Apr 25, 2024
@arthanson arthanson added beta Concerns a bug/feature in a beta release severity: medium Results in substantial degraded or broken functionality for specfic workflows and removed status: needs triage This issue is awaiting triage by a maintainer labels Apr 26, 2024
@jeremystretch jeremystretch added the status: accepted This issue has been accepted for implementation label Apr 26, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 31, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
beta Concerns a bug/feature in a beta release severity: medium Results in substantial degraded or broken functionality for specfic workflows 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