Code

Ticket #9119: ignore_non_field_params_against_9066.diff

File ignore_non_field_params_against_9066.diff, 1.0 KB (added by fas, 6 years ago)

Only use field lookup parameters to filter the results, ignore others.

Line 
1Index: django/contrib/admin/views/main.py
2===================================================================
3--- django/contrib/admin/views/main.py  (revision 9066)
4+++ django/contrib/admin/views/main.py  (working copy)
5@@ -181,8 +181,17 @@
6                 # 'key' will be used as a keyword argument later, so Python
7                 # requires it to be a string.
8                 del lookup_params[key]
9-                lookup_params[smart_str(key)] = value
10+                key = smart_str(key)
11+                lookup_params[key] = value
12 
13+            # ignore parameters that are no field lookups
14+            from django.db.models.sql.constants import LOOKUP_SEP
15+            try:
16+                field = self.opts.get_field(key.split(LOOKUP_SEP)[0])
17+            except models.FieldDoesNotExist:
18+                del lookup_params[key]
19+                continue
20+
21             # if key ends with __in, split parameter into separate values
22             if key.endswith('__in'):
23                 lookup_params[key] = value.split(',')