Skip to content

Event Rules on models that reference image files generate error #20873

@tyler-8

Description

@tyler-8

NetBox Edition

NetBox Community

NetBox Version

v4.4.5

Python Version

3.12

Steps to Reproduce

  1. Create an Event Rule for DCIM | device type or extras | image attachement
  2. Create a new Device Type with a front and/or rear image and click 'Create`

Expected Behavior

In GUI, new device type page loads without errors.

Observed Behavior

Image
Traceback (most recent call last):
  File "/opt/netbox/current/venv-py3/lib/python3.12/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
               ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/releases/netbox-4.4.5/netbox/netbox/middleware.py", line 40, in __call__
    with apply_request_processors(request):
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/.pyenv/versions/3.12.8/lib/python3.12/contextlib.py", line 144, in __exit__
    next(self.gen)
    ^^^^^^^^^^^^^^
  File "/opt/netbox/releases/netbox-4.4.5/netbox/utilities/request.py", line 102, in apply_request_processors
    with ExitStack() as stack:
         ^^^^^^^^^^^
  File "/opt/netbox/.pyenv/versions/3.12.8/lib/python3.12/contextlib.py", line 610, in __exit__
    raise exc_details[1]
    ^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/.pyenv/versions/3.12.8/lib/python3.12/contextlib.py", line 595, in __exit__
    if cb(*exc_details):
       ^^^^^^^^^^^^^^^^
  File "/opt/netbox/.pyenv/versions/3.12.8/lib/python3.12/contextlib.py", line 144, in __exit__
    next(self.gen)
    ^^^^^^^^^^^^^^
  File "/opt/netbox/releases/netbox-4.4.5/netbox/netbox/context_managers.py", line 24, in event_tracking
    flush_events(events)
    ^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/releases/netbox-4.4.5/netbox/extras/events.py", line 198, in flush_events
    func(events)
    ^^^^^^^^^^^^
  File "/opt/netbox/releases/netbox-4.4.5/netbox/extras/events.py", line 179, in process_event_queue
    process_event_rules(
    ^
  File "/opt/netbox/releases/netbox-4.4.5/netbox/extras/events.py", line 125, in process_event_rules
    rq_queue.enqueue(
    ^
  File "/opt/netbox/current/venv-py3/lib/python3.12/site-packages/rq/queue.py", line 1011, in enqueue
    return self.enqueue_call(
          
  File "/opt/netbox/current/venv-py3/lib/python3.12/site-packages/django_rq/queues.py", line 75, in enqueue_call
    return self.original_enqueue_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/current/venv-py3/lib/python3.12/site-packages/django_rq/queues.py", line 71, in original_enqueue_call
    return super(DjangoRQ, self).enqueue_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/current/venv-py3/lib/python3.12/site-packages/rq/queue.py", line 743, in enqueue_call
    return self.enqueue_job(job, pipeline=pipeline, at_front=at_front)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/current/venv-py3/lib/python3.12/site-packages/rq/queue.py", line 1142, in enqueue_job
    return self._enqueue_job(job, pipeline=pipeline, at_front=at_front)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/current/venv-py3/lib/python3.12/site-packages/rq/queue.py", line 1170, in _enqueue_job
    job.save(pipeline=pipe)
    ^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/current/venv-py3/lib/python3.12/site-packages/rq/job.py", line 1117, in save
    mapping = self.to_dict(include_meta=include_meta, include_result=include_result)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/current/venv-py3/lib/python3.12/site-packages/rq/job.py", line 1031, in to_dict
    'data': zlib.compress(self.data),
                          ^^^^^^^^^
  File "/opt/netbox/current/venv-py3/lib/python3.12/site-packages/rq/job.py", line 570, in data
    self._data = self.serializer.dumps(job_tuple)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/current/venv-py3/lib/python3.12/site-packages/PIL/JpegImagePlugin.py", line 399, in __getstate__
    return super().__getstate__() + [self.layers, self.layer]
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/current/venv-py3/lib/python3.12/site-packages/PIL/ImageFile.py", line 257, in __getstate__
    return super().__getstate__() + [self.filename]
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/current/venv-py3/lib/python3.12/site-packages/PIL/Image.py", line 739, in __getstate__
    im_data = self.tobytes()  # load image first
              ^^^^^^^^^^^^^^
  File "/opt/netbox/current/venv-py3/lib/python3.12/site-packages/PIL/Image.py", line 785, in tobytes
    self.load()
    ^^^^^^^^^^^
  File "/opt/netbox/current/venv-py3/lib/python3.12/site-packages/PIL/ImageFile.py", line 302, in load
    seek = self.fp.seek
           ^^^^^^^^^^^^

Exception Type: AttributeError at /dcim/device-types/add/
Exception Value: 'NoneType' object has no attribute 'seek'
Raised during: dcim.views.DeviceTypeEditView

Stack Overflow with related discussion: https://stackoverflow.com/a/77483484

FWIW I do not think this was an issue in NetBox v4.1.

Metadata

Metadata

Assignees

Labels

netboxseverity: lowDoes not significantly disrupt application functionality, or a workaround is availablestatus: acceptedThis issue has been accepted for implementationtype: bugA confirmed report of unexpected behavior in the application

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions