-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Description
NetBox Edition
NetBox Community
NetBox Version
v4.4.0
Python Version
3.12
Steps to Reproduce
- Upload an image attachment with a name containing forward slashes (e.g., "Rack Picture 7/10/24")
- Run
python manage.py reindex --lazy - 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.