#25131 closed Uncategorized (needsinfo)
language changes randomly
| Reported by: | va-dev | Owned by: | nobody | 
|---|---|---|---|
| Component: | Internationalization | Version: | 1.8 | 
| Severity: | Normal | Keywords: | |
| Cc: | va-dev | Triage Stage: | Unreviewed | 
| Has patch: | no | Needs documentation: | no | 
| Needs tests: | no | Patch needs improvement: | no | 
| Easy pickings: | no | UI/UX: | no | 
Description
I use decorator for temporal language activation:
from django.utils.translation import get_language, activate
def wrap_language(f):
    @wraps(f)
    def wrapper(request, *args, **kwargs):
        company = get_company(request)
        cs = retrieve_company_settings(company)
        current_language = get_language()
        activate(cs.language.lower())
        response = f(request, *args, **kwargs)
        activate(current_language)
        return response
    return wrapper
I've met a problem that when i frequently update any page of my website, language sometimes changes randomly.
My gunicorn command:
gunicorn mysite.wsgi:application -b unix:/tmp/mysite.sock --workers 5 --threads 5
Change History (3)
comment:1 by , 10 years ago
| Cc: | added | 
|---|
comment:2 by , 10 years ago
| Resolution: | → needsinfo | 
|---|---|
| Status: | new → closed | 
comment:3 by , 10 years ago
In any case, try at least to enclose your response =  line in a try/finally bloc, to restore the language even if an exception occurred.
  Note:
 See   TracTickets
 for help on using tickets.
    
There's not enough information in this report to point to a bug in Django. Please see TicketClosingReasons/UseSupportChannels and reopen the ticket with more details (such as a sample project we can use to reproduce the problem) if it turns out not to be a bug in your own code.