Fixes #3292: Ignore empty URL query parameters

This commit is contained in:
Jeremy Stretch 2019-06-24 11:00:18 -04:00
parent 70ef6a69ee
commit 653770ede9
2 changed files with 6 additions and 2 deletions

View File

@ -5,6 +5,7 @@ v2.6.1 (FUTURE)
* [#3275](https://github.com/digitalocean/netbox/issues/3275) - Fix error when adding power outlets to a device type
* [#3279](https://github.com/digitalocean/netbox/issues/3279) - Reset the PostgreSQL sequence for Tag and TaggedItem IDs
* [#3290](https://github.com/digitalocean/netbox/issues/3290) - Fix server error when viewing cascaded PDUs
* [#3292](https://github.com/digitalocean/netbox/issues/3292) - Ignore empty URL query parameters
---

View File

@ -9,7 +9,7 @@ from extras.models import Tag
def multivalue_field_factory(field_class):
"""
Given a form field class, return a subclass capable of accepting multiple values. This allows us to OR on multiple
filter values while maintaining the field's built-in vlaidation. Example: GET /api/dcim/devices/?name=foo&name=bar
filter values while maintaining the field's built-in validation. Example: GET /api/dcim/devices/?name=foo&name=bar
"""
class NewField(field_class):
widget = forms.SelectMultiple
@ -17,7 +17,10 @@ def multivalue_field_factory(field_class):
def to_python(self, value):
if not value:
return []
return [super(field_class, self).to_python(v) for v in value]
return [
# Only append non-empty values (this avoids e.g. trying to cast '' as an integer)
super(field_class, self).to_python(v) for v in value if v
]
return type('MultiValue{}'.format(field_class.__name__), (NewField,), dict())