[Answered ]-Ugettext not providing correct values in a view ("caching" the old language value)


This is the old Python default arguments gotcha once again.

The default values for the create_render_args function are evaluated when the function is first imported, which is probably when the server process starts up. Processes in WSGI last for multiple requests, which explains why the value is cached between views, but there are usually multiple processes running at once, which explains why sometimes you see the correct version.

I’m not sure why using ugettext_lazy isn’t the answer for you – that seems to be exactly its use case – but otherwise you could just use the raw text itself as the default and do the _ call within the function.

Leave a comment