Skip to content
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

[3.8.0+] Django "active" language is not safe to use with ASGI #475

Open
sshishov opened this issue Oct 4, 2024 · 7 comments
Open

[3.8.0+] Django "active" language is not safe to use with ASGI #475

sshishov opened this issue Oct 4, 2024 · 7 comments

Comments

@sshishov
Copy link

sshishov commented Oct 4, 2024

I can reproduce this issue with version 3.8.0 and above.

Create django project with 1 view which will return you active user language:

from django.utils import translation

def view(request):
    return translation.get_language()

Start django under ASGI (using daphne for instance)

Then in 2 terminals/terminal-tabs start the CURL operation for this enpoint with different language in cookies:

while true; do curl ...; done;

And you will observer that every request is affecting the response on another terminal/terminal-tab.

It will be like this:

language: X
langauge: Y
language: X

Meaning it is not consistent when it should be. Especially we are interested in Content-Language header which is set automatically and for us the value of this header is affected by other requests...

NOTE: Downgrading asgiref to version below mentioned (for instance 3.7.2 fixes the issue.

Possibly related: #473

@carltongibson
Copy link
Member

@sshishov can you confirm your versions for Django and other dependencies you’re using here please?

@sshishov
Copy link
Author

sshishov commented Oct 4, 2024

Hi @carltongibson

My system:
MacOs + Docker (ubuntu)
Python: Python 3.11.10
Django: Django==4.2.15
ASGIRef: asgiref==3.8.1

For other dependencies, what exactly do you want as we have a lot?

I can try to create the repo with and try to reproduce there. Then share with you guys.
The same issue happened with:

  • Django + Gunicorn + Uvicorn (as workers)
  • Django + Channels + Daphne

@carltongibson
Copy link
Member

@sshishov That's fine. That's the core ones.

If you had a minimal test reproduction that would save me a cycle creating one myself (but no stress).

Thanks!

@carltongibson
Copy link
Member

@sshishov I pushed #477 in the local-task-fix branch that you could try out if you had a moment.

@carltongibson
Copy link
Member

Hi @sshishov can I ask you to test the branch in #478 and confirm it resolves you issue? Thanks. 🙏

@sshishov
Copy link
Author

Hi @carltongibson, going to test it in 1-2 days. I guess I can test against main now (as the MR has been merged), correct?

@carltongibson
Copy link
Member

@sshishov Correct. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants