#10910 closed (invalid)
Unicode dictionary keys cause TypeError when used as arguments to filter()
Reported by: | mostrovsky | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I'm using dictionaries to pass arguments to a filter. If the keys of the dictionary are unicode, this causes a TypeError similar to the ones seen in previous tickets (see #10645, which fixed this problem from the admin side of things)
>>> filter_args = {u'date_created':'2009-01-01'} >>> MyClass.objects.filter(**filter_args) >>> TypeError: filter() keywords must be strings
Of course, casting the keys by using str() fixes the problem.
This behavior can bee seen on trunk, revision 10630, with python2.5
Change History (3)
comment:1 by , 16 years ago
Version: | 1.0 → SVN |
---|
comment:2 by , 16 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
This isn't a bug with Django. You can only use the str type for parameter names when calling Python functions. That applies for kwargs as well. It's normal Python behaviour and you should get into the habit of only using str objects as the keys in dictionaries passed as kwargs. So the solution to your problem is "don't do that".
Change Version field value to SVN as per ticket description.