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

This commit is contained in:
Jeremy Stretch 2018-11-26 14:05:57 -05:00
parent 2bae50f501
commit 7d8ae5e763
2 changed files with 7 additions and 1 deletions

View File

@ -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 * [#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 * [#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 * [#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 ## API Changes

View File

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