Skip to content

New image attachment index breaks if image name contains a slash #20236

@fabi125

Description

@fabi125

Deployment Type

Self-hosted

NetBox Version

v4.4.0

Python Version

3.12

Steps to Reproduce

  1. Go to a random site/rack/device, e.g. https://demo.netbox.dev/dcim/racks/1/
  2. Click on "Attach an image"
  3. Select a random image and then enter as the name something that contains a slash, e.g. todays date 9/3/25

Expected Behavior

Image gets added or an error is shown that says can't use a slash in the name.

Observed Behavior

<class 'IndexError'>

list index out of range

which comes from here:

  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

The new index and code was added in #18990. This is currently preventing us from upgrading to v4.4 as we seem to have image attachments with slashes in their names in the database and on the filesystem (which are even nested into subfolders oO):

-[ RECORD 3 ]--+-------------------------------------------------------------
id             | 134
object_id      | 12
image          | image-attachments/rack_12_5/31/23.jpg
image_height   | 4032
image_width    | 3024
name           | 5/31/23
created        | 2023-06-01 15:43:29.221191+00
object_type_id | 29
last_updated   | 2023-06-01 15:43:29.221203+00
$ find media/image-attachments/rack_12_5/
media/image-attachments/rack_12_5/
media/image-attachments/rack_12_5/31
media/image-attachments/rack_12_5/31/23.jpg

Metadata

Metadata

Assignees

Labels

severity: 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