-
Notifications
You must be signed in to change notification settings - Fork 295
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
Error - "The translation infrastructure cannot be initialized before the " #203
Comments
It's generally a symptom of a wrong import order in your project. Maybe the full traceback could give us a hint about what's happening. |
Here is the traceback...
|
OK, thanks, this shows the bug is valid. |
Note that this will be difficult to fix if we want to keep the sorting functionality, as the choices are consumed very soon in the form creation process. |
@chadsaun Hey. Im unable to reproduce this issue. Could you check that you have |
I'm seeing this error too. My wsgi.py has |
If this is happening because of an entry in the |
Have the same bug. I tried to migrate from the old version
Any import, even simle |
I am also encountering this but only when I run celery on Heroku. Does not happen when I run celery locally. Sounds like I may have a setup issue but I am not sure where. Any ideas for me? |
Only looking at the traceback can show what is possible to prevent this error. Generally, try to not trigger import of localflavor stuff in the init file of any app. |
The wsgi loader calls django.setup(), which loads the haystack app, which calls QueuedSignalProcessor.setup() in tendenci/apps/search/signals.py, which imports search_indexes.py in the forms_builder Tendenci app, which imports models.py, which imports localflavor.us.us_states from Django. localflavor.us.states versions 1.2 and 1.3 have a bug that causes an exception if the module is imported during Django initialization. See: django/django-localflavor#203 This breaks the search index for the forms_builder Tendenci app. localflavor.us.states is not actually needed by search_indexes.py, so simply ignore the exception that is thrown when it is imported during Django initialization.
Commit 4369237 introduced lazy translations for US state names. However, US_STATES, STATE_CHOICES, and USPS_CHOICES are sorted at import time based on the translated state names. This causes two problems: 1) If localflavor.us is imported during Django initialization, then an exception will be thrown because translations cannot be made during Django initialization. (See #203) 2) When the run-time translations are different than the import-time translations, US_STATES, STATE_CHOICES, and USPS_CHOICES are not re-sorted based on the run-time translations, so those lists may be mis-sorted. This commit corrects these problems by lazily sorting US_STATES, STATE_CHOICES, and USPS_CHOICES. Unfortunately, while this works as expected in most cases, the lazy evaluation may not work as expected in every case due to internal tuple optimizations in the Python interpreter. For example, `US_STATES + ('XX', _('Select a State'))` works as expected, but `('XX', _('Select a State')) + US_STATES` throws 'TypeError: can only concatenate tuple (not "__proxy__") to tuple' because Python concatenates the tuples entirely in C code without making any Python code calls to the US_STATES object, which prevents US_STATES from being lazily generated before the concatenation is processed. To work around this, you can use a slice index to force a Python code call on the object before any other operations are processed: `('XX', _('Select a State')) + US_STATES[:]`
I just installed localflavor and then added the
widgets
part to my form.Then I get this error below. But as soon as I comment out the
widgets
part from my form, the error goes away. Any ideas?The text was updated successfully, but these errors were encountered: