-
-
Notifications
You must be signed in to change notification settings - Fork 484
QueryDict __getitem__ wrong type #1010
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
QueryDict __getitem__ wrong type #1010
Comments
СС @intgr |
You would think so, but actually: In [6]: from django.http.request import QueryDict
In [7]: q = QueryDict(mutable=True)
In [8]: q.setlist('foo', ['value'])
In [9]: q['foo']
Out[9]: 'value'
In [10]: q.setlist('bar', [])
In [11]: q['bar']
Out[11]: [] # <-- !?!? I would argue this is a bug in Django, but I don't think this has been reported upstream. #909 added the hint that
It looks like you're using django-rest-framework, This can be fixed by using (But if this continues to cause problems, personally I'm not opposed to reverting the complexity created for |
Cc: @sterliakov |
Bug report
What's wrong
In our code base I get
Type of "self.request.query_params["start_date"]" is "str | List[object]"
after upgradingdjango-stubs
from1.8.0
to1.12.0
.Reproducible example:
Type of "query_params["foo"]" is "str | List[object]"
According to Django docs,
QueryDict.__getitem__
always returns one value, never a list:How is that should be
Type of "query_params["foo"]" should be "str"
System information
python:3.9.1
Docker imagepython
version: 3.9.1django
version: 4.0.1mypy
version: 0.931django-stubs
version: 1.12.0-django-stubs-ext
version:The text was updated successfully, but these errors were encountered: