﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
24277	Passing a dict with 2 keys to a queryset filter passes erroneously.	Keryn Knight	alexandrinaw	"It's reasonably common to do this:
{{{
kws = {'first_name': 'test', 'is_superuser': False}
get_user_model().objects.filter(**kws)
}}}
when building up a set of queryset filters, at least if you don't need to introduce ORs (via `Q()`).

However, if you forget, or accidentally don't star-expand the dictionary:
{{{
get_user_model().objects.filter(kws)
}}}
You instead get back a queryset with the wrong SQL applied, specifically, above it yields `WHERE first_name = 'is_superuser'`, though that may be a function of the relative stableness of dicts on Python2.

This is in contrast to if your `kws` dict contains 1, or 3+ keys, which correctly error loudly and let you know you screwed up, yielding either:
{{{
ValueError: need more than 1 value to unpack
ValueError: too many values to unpack (expected 2)
}}}
Or if you're lucky, and the `get_prep_lookup` can figure out you've been silly:
{{{
# using kws = {'id': 1, 'is_superuser': False}
ValueError: invalid literal for int() with base 10: 'is_superuser'
}}}
(This last is a relatively recent addition in master, as far as I can tell, having just pulled up to date from just after 1.8a I think)

The issue itself stems from [https://github.com/akaariai/django/blob/a7260199ad63cd07e4df85438cb283413978fad2/django/db/models/sql/query.py#L1119 Query.build_filter], and the specific line which causes the problem I think would survive the changes being made in #24267."	Cleanup/optimization	closed	Database layer (models, ORM)	dev	Normal	fixed		django@… Nina Zakharenko alexandrinaw	Ready for checkin	1	0	0	1	0	0
