Browse Source

Fixes #2609: Fixed exception when ChoiceField integer value is passed as a string

Jeremy Stretch 7 years ago
parent
commit
7d8ae5e763
2 changed files with 7 additions and 1 deletions
  1. 1 0
      CHANGELOG.md
  2. 6 1
      netbox/utilities/api.py

+ 1 - 0
CHANGELOG.md

@@ -61,6 +61,7 @@ NetBox now supports modeling physical cables for console, power, and interface c
 * [#2601](https://github.com/digitalocean/netbox/issues/2601) - Added a `description` field to pass-through ports
 * [#2602](https://github.com/digitalocean/netbox/issues/2602) - Return HTTP 204 when no new IPs/prefixes are available for provisioning
 * [#2608](https://github.com/digitalocean/netbox/issues/2608) - Fixed null `outer_unit` error on rack import
+* [#2609](https://github.com/digitalocean/netbox/issues/2609) - Fixed exception when ChoiceField integer value is passed as a string
 
 ## API Changes
 

+ 6 - 1
netbox/utilities/api.py

@@ -78,12 +78,17 @@ class ChoiceField(Field):
         return data
 
     def to_internal_value(self, data):
-        # Hotwiring boolean values
         if hasattr(data, 'lower'):
+            # Hotwiring boolean values from string
             if data.lower() == 'true':
                 return True
             if data.lower() == 'false':
                 return False
+            # Check for string representation of an integer (e.g. "123")
+            try:
+                data = int(data)
+            except ValueError:
+                pass
         return data