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

Fixes #3292: Ignore empty URL query parameters

Jeremy Stretch 6 лет назад
Родитель
Сommit
653770ede9
2 измененных файлов с 6 добавлено и 2 удалено
  1. 1 0
      CHANGELOG.md
  2. 5 2
      netbox/utilities/filters.py

+ 1 - 0
CHANGELOG.md

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

+ 5 - 2
netbox/utilities/filters.py

@@ -9,7 +9,7 @@ from extras.models import Tag
 def multivalue_field_factory(field_class):
 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
     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):
     class NewField(field_class):
         widget = forms.SelectMultiple
         widget = forms.SelectMultiple
@@ -17,7 +17,10 @@ def multivalue_field_factory(field_class):
         def to_python(self, value):
         def to_python(self, value):
             if not value:
             if not value:
                 return []
                 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())
     return type('MultiValue{}'.format(field_class.__name__), (NewField,), dict())