Просмотр исходного кода

Fixes #6217: Disallow passing of string values for integer custom fields

jeremystretch 4 лет назад
Родитель
Сommit
1658d7ae86
2 измененных файлов с 2 добавлено и 3 удалено
  1. 1 0
      docs/release-notes/version-2.11.md
  2. 1 3
      netbox/extras/models/customfields.py

+ 1 - 0
docs/release-notes/version-2.11.md

@@ -11,6 +11,7 @@
 ### Bug Fixes
 ### Bug Fixes
 
 
 * [#6064](https://github.com/netbox-community/netbox/issues/6064) - Fix object permission assignments for user and group models
 * [#6064](https://github.com/netbox-community/netbox/issues/6064) - Fix object permission assignments for user and group models
+* [#6217](https://github.com/netbox-community/netbox/issues/6217) - Disallow passing of string values for integer custom fields
 * [#6284](https://github.com/netbox-community/netbox/issues/6284) - Avoid sending redundant webhooks when adding/removing tags
 * [#6284](https://github.com/netbox-community/netbox/issues/6284) - Avoid sending redundant webhooks when adding/removing tags
 * [#6496](https://github.com/netbox-community/netbox/issues/6496) - Fix upgrade script when Python installed in nonstandard path
 * [#6496](https://github.com/netbox-community/netbox/issues/6496) - Fix upgrade script when Python installed in nonstandard path
 * [#6502](https://github.com/netbox-community/netbox/issues/6502) - Correct permissions evaluation for running a report via the REST API
 * [#6502](https://github.com/netbox-community/netbox/issues/6502) - Correct permissions evaluation for running a report via the REST API

+ 1 - 3
netbox/extras/models/customfields.py

@@ -286,9 +286,7 @@ class CustomField(BigIDModel):
 
 
             # Validate integer
             # Validate integer
             if self.type == CustomFieldTypeChoices.TYPE_INTEGER:
             if self.type == CustomFieldTypeChoices.TYPE_INTEGER:
-                try:
-                    int(value)
-                except ValueError:
+                if type(value) is not int:
                     raise ValidationError("Value must be an integer.")
                     raise ValidationError("Value must be an integer.")
                 if self.validation_minimum is not None and value < self.validation_minimum:
                 if self.validation_minimum is not None and value < self.validation_minimum:
                     raise ValidationError(f"Value must be at least {self.validation_minimum}")
                     raise ValidationError(f"Value must be at least {self.validation_minimum}")