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

Closed
opened 2025-12-29 21:51:00 +01:00 by adam · 1 comment
Owner

Originally created by @tyler-8 on GitHub (Nov 24, 2025).

Originally assigned to: @arthanson on GitHub.

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.

Originally created by @tyler-8 on GitHub (Nov 24, 2025). Originally assigned to: @arthanson on GitHub. ### 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 <img width="945" height="633" alt="Image" src="https://github.com/user-attachments/assets/e095e9fe-03e9-4c55-9f1b-bfc5d5c33492" /> ``` 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.
adam added the type: bugstatus: acceptednetboxseverity: low labels 2025-12-29 21:51:00 +01:00
adam closed this issue 2025-12-29 21:51:00 +01:00
Author
Owner

@sol1-matt commented on GitHub (Nov 27, 2025):

I got this same error under the same conditions

  • An event rule with an object type of dcim.device_type
  • Create or update a device type with a new image

On save the server error appears

<class 'AttributeError'>

'NoneType' object has no attribute 'seek'

Additional info

  • The device type object is still saved successfully with the new/updated image
  • The webhook event fails to trigger
  • The error doesn't occur when clearing the image from the device type and the webhook does trigger on delete
  • The webhook does trigger when saving without a new or updated image

With the installation I'm seeing this on, the device type/webhook combo has been in place for about a year. It is a reasonable assumption that the users would have been adding images to device types consistently over that time.

The current version being run is 4.4.5, this is the first time this error has been reported for this installation.
The recent previous versions for this installation are 4.3.4, 4.2.8 and 4.1.7. The error was not reported on these versions.

@sol1-matt commented on GitHub (Nov 27, 2025): I got this same error under the same conditions - An event rule with an object type of `dcim.device_type` - Create or update a device type with a new image On save the server error appears ``` <class 'AttributeError'> 'NoneType' object has no attribute 'seek' ``` Additional info - The device type object is still saved successfully with the new/updated image - The webhook event fails to trigger - The error doesn't occur when clearing the image from the device type and the webhook does trigger on delete - The webhook does trigger when saving without a new or updated image With the installation I'm seeing this on, the device type/webhook combo has been in place for about a year. It is a reasonable assumption that the users would have been adding images to device types consistently over that time. The current version being run is 4.4.5, this is the first time this error has been reported for this installation. The recent previous versions for this installation are 4.3.4, 4.2.8 and 4.1.7. The error was not reported on these versions.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#11868