CustomField.validate does not check the length of a text field #6639

Closed
opened 2025-12-29 19:43:23 +01:00 by adam · 2 comments
Owner

Originally created by @PieterL75 on GitHub (Jul 8, 2022).

Originally assigned to: @jeremystretch on GitHub.

NetBox version

v3.2.5

Python version

3.9

Steps to Reproduce

  1. create a custom field of the type 'text'
  2. use the API to update that text field with a string > 255 characters

Expected Behavior

A validation error should be thrown, as custom TEXT fields should be limited to 255 characters

Observed Behavior

The length validation is only done in the 'form' and not in validate()

https://github.com/netbox-community/netbox/blob/develop/netbox/extras/models/customfields.py#L457-L462

This part should also check the length of a TEXT custom field:

                if self.type == CustomFieldTypeChoices.TYPE_TEXT and len(value) > 255:
                    raise ValidationError(f"Value cannot contain more than 255 characters")
Originally created by @PieterL75 on GitHub (Jul 8, 2022). Originally assigned to: @jeremystretch on GitHub. ### NetBox version v3.2.5 ### Python version 3.9 ### Steps to Reproduce 1. create a custom field of the type 'text' 2. use the API to update that text field with a string > 255 characters ### Expected Behavior A validation error should be thrown, as custom TEXT fields should be limited to 255 characters ### Observed Behavior The length validation is only done in the 'form' and not in validate() https://github.com/netbox-community/netbox/blob/develop/netbox/extras/models/customfields.py#L457-L462 This part should also check the length of a TEXT custom field: ``` if self.type == CustomFieldTypeChoices.TYPE_TEXT and len(value) > 255: raise ValidationError(f"Value cannot contain more than 255 characters") ```
adam added the type: bugstatus: accepted labels 2025-12-29 19:43:23 +01:00
adam closed this issue 2025-12-29 19:43:23 +01:00
Author
Owner

@jeremystretch commented on GitHub (Jul 8, 2022):

IIRC we removed the length limitation when we moved custom field data to a JSON field on the object back in... whenever that was. The docs do still make reference to it, though.

So do we want to enforce the limit consistently, or remove it altogether?

@jeremystretch commented on GitHub (Jul 8, 2022): IIRC we removed the length limitation when we moved custom field data to a JSON field on the object back in... whenever that was. The docs do still make reference to it, though. So do we want to enforce the limit consistently, or remove it altogether?
Author
Owner

@PieterL75 commented on GitHub (Jul 8, 2022):

If there use no real technical reason for the 255 characters, then I'd suggest to remove the limitation.
Text is then a one-line field and longtext is then the multi line field.
Then the bug report changes to : custom field of type text is limited to 255 characters in the form...

@PieterL75 commented on GitHub (Jul 8, 2022): If there use no real technical reason for the 255 characters, then I'd suggest to remove the limitation. Text is then a one-line field and longtext is then the multi line field. Then the bug report changes to : custom field of type text is limited to 255 characters in the form...
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#6639