You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The file base_session.pyi contains the stubs for AbstractBaseSession. The stub for the method get_decoded is wrong.
It is Dict[str, int] but obviously the decoded session can also contain strings.
How is that should be
Steps to reproduce:
Have any django project running with session login.
Login so that there is at least one session in the database.
Open the python shell with python manage.py shell
Run the following code from within the shell:
from django.contrib.sessions.models import Session
s = Session.objects.first()
s.get_decoded()
# Example response:
# {'_auth_user_id': '1', '_auth_user_backend': 'django.contrib.auth.backends.ModelBackend', '_auth_user_hash': '1c92e5298f2609bd14615aef4f2bd07a13a7e741b8acc475623ae3f1386d4879'}
As you can see event the auth_user_id is a string. Therefore I think the stub should be Dict[str, str] but at the moment I'm not sure if it can include numbers, so Dict[str, Union[str, int]] might also be correct.
System information
django-stubs==1.13.0
The text was updated successfully, but these errors were encountered:
That seems fine, probably the most correct. I didn't notice that it changed recently. I'm not sure if TypedDict is the correct way to go, as the session can be extended with any key you want. In my opinion this issue can be closed.
I'm not sure this makes sense to change from dict[str, Any], especially as TypedDict doesn't always play nicely. People may not use django.contrib.auth or the session may be empty, so keys added to support session variables added there would need to be NotRequired, or we can use total=False for the whole TypedDict:
Unfortunately, the session can also contain virtually anything. It's not limited to what django.contrib.auth adds. Until TypedDict supports extra values that are not defined we cannot change from dict[str, Any].
Bug report
I found a wrong stub.
What's wrong
The file
base_session.pyi
contains the stubs for AbstractBaseSession. The stub for the methodget_decoded
is wrong.It is
Dict[str, int]
but obviously the decoded session can also contain strings.How is that should be
Steps to reproduce:
python manage.py shell
Run the following code from within the shell:
As you can see event the auth_user_id is a string. Therefore I think the stub should be
Dict[str, str]
but at the moment I'm not sure if it can include numbers, soDict[str, Union[str, int]]
might also be correct.System information
django-stubs==1.13.0
The text was updated successfully, but these errors were encountered: