IndexError during reindex command when ImageAttachment filenames contain forward slashes #11601

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

Originally created by @arcticash on GitHub (Sep 11, 2025).

NetBox Edition

NetBox Community

NetBox Version

v4.4.0

Python Version

3.12

Steps to Reproduce

  1. Upload an image attachment with a name containing forward slashes (e.g., "Rack Picture 7/10/24")
  2. Run python manage.py reindex --lazy
  3. Command fails when processing the ImageAttachment

Example Problematic Filenames:

image-attachments/rack_66_Rack Picture 7/10/24.jpeg → os.path.basename() returns 24.jpeg
image-attachments/location_279_Room 106A 7/10/24.jpeg → os.path.basename() returns 24.jpeg

Expected Behavior

The update should complete successfully by altering the names of the objects to remove the problem symbols, or fail and specifying what the problem is.

Observed Behavior

The manage.py reindex --lazy command fails with an IndexError: list index out of range when processing ImageAttachment objects that have filenames containing forward slashes.

Error Traceback:

File "/opt/netbox/netbox/extras/models/models.py", line 731, in filename
  return os.path.basename(self.image.name).split('_', 2)[2]
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^
IndexError: list index out of range

Suspected Root Cause:

Disclaimer - this is what AI thinks the problem is!
The ImageAttachment.filename property assumes all filenames follow the pattern prefix_objectid_actualfilename.ext and tries to extract the third component after splitting on underscores. However, when image names contain forward slashes (like dates "7/10/24"), os.path.basename() only returns the portion after the last slash, which may not contain the expected underscore pattern.

Originally created by @arcticash on GitHub (Sep 11, 2025). ### NetBox Edition NetBox Community ### NetBox Version v4.4.0 ### Python Version 3.12 ### Steps to Reproduce 1. Upload an image attachment with a name containing forward slashes (e.g., "Rack Picture 7/10/24") 2. Run `python manage.py reindex --lazy` 3. Command fails when processing the `ImageAttachment` ## Example Problematic Filenames: image-attachments/rack_66_Rack Picture 7/10/24.jpeg → os.path.basename() returns 24.jpeg image-attachments/location_279_Room 106A 7/10/24.jpeg → os.path.basename() returns 24.jpeg ### Expected Behavior The update should complete successfully by altering the names of the objects to remove the problem symbols, or fail and specifying what the problem is. ### Observed Behavior The `manage.py reindex --lazy` command fails with an `IndexError: list index out of range` when processing `ImageAttachment` objects that have filenames containing forward slashes. ## Error Traceback: ``` File "/opt/netbox/netbox/extras/models/models.py", line 731, in filename return os.path.basename(self.image.name).split('_', 2)[2] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^ IndexError: list index out of range ``` ## Suspected Root Cause: _Disclaimer - this is what AI thinks the problem is!_ The `ImageAttachment.filename` property assumes all filenames follow the pattern prefix_objectid_actualfilename.ext and tries to extract the third component after splitting on underscores. However, when image names contain forward slashes (like dates "7/10/24"), `os.path.basename()` only returns the portion after the last slash, which may not contain the expected underscore pattern.
adam added the type: bugstatus: duplicate labels 2025-12-29 21:47:30 +01:00
adam closed this issue 2025-12-29 21:47:30 +01:00
Author
Owner

@arcticash commented on GitHub (Sep 11, 2025):

Spent some more time digging through the open issues and I think this is a duplicate of #20236 but just raised in the different way, happy for this to be closed as the fix is already pending under #20315

@arcticash commented on GitHub (Sep 11, 2025): Spent some more time digging through the open issues and I think this is a duplicate of #20236 but just raised in the different way, happy for this to be closed as the fix is already pending under #20315
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#11601