Code

Opened 4 years ago

Closed 4 years ago

Last modified 3 years ago

#13234 closed (fixed)

cannot import name trans_real

Reported by: roklenardic Owned by: nobody
Component: Internationalization Version: master
Severity: Keywords:
Cc: jezdez Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Having updated to the latest trunk this morning, one of my applications would not even start. This is what I get:
rok@machine:~/path/to/application$ ./manage.py runserver
Error: cannot import name trans_real

I updated again a second ago to revision 12873 and still the same message.
So I tried reverting back to a revision 12788 (I remember the app working 2 weeks ago) and it works. So it seems some core django changes have broken it inbetween. Any idea?

Attachments (0)

Change History (11)

comment:1 Changed 4 years ago by Alex

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Can you post a full traceback, this is clearly the result of [12866] but I'm not sure how it's possible. Also what Python version?

comment:2 Changed 4 years ago by jezdez

  • Cc jezdez added

comment:3 Changed 4 years ago by kmtracey

I suspect the full traceback is not being shown -- what is in the description looks like what runserver does for some errors. To get the full traceback might need to find where in runserver the exception is being caught and swallowing the traceback, and change it to not do that.

comment:4 Changed 4 years ago by anonymous

[Sun Mar 28 15:15:02 2010] [error] [client 137.112.132.137] Traceback (most recent call last):
[Sun Mar 28 15:15:02 2010] [error] [client 137.112.132.137]   File "/usr/lib/python2.5/site-packages/mod_python/importer.py", line 1537, in HandlerDispatch\n    default=default_handler, arg=req, silent=hlist.silent)
[Sun Mar 28 15:15:02 2010] [error] [client 137.112.132.137]   File "/usr/lib/python2.5/site-packages/mod_python/importer.py", line 1202, in _process_target\n    module = import_module(module_name, path=path)
[Sun Mar 28 15:15:02 2010] [error] [client 137.112.132.137]   File "/usr/lib/python2.5/site-packages/mod_python/importer.py", line 304, in import_module\n    return __import__(module_name, {}, {}, ['*'])
[Sun Mar 28 15:15:02 2010] [error] [client 137.112.132.137]   File "/usr/lib/python2.5/site-packages/django/core/handlers/modpython.py", line 4, in <module>\n    from django import http
[Sun Mar 28 15:15:02 2010] [error] [client 137.112.132.137]   File "/usr/lib/python2.5/site-packages/django/http/__init__.py", line 15, in <module>\n    from django.http.multipartparser import MultiPartParser
[Sun Mar 28 15:15:02 2010] [error] [client 137.112.132.137]   File "/usr/lib/python2.5/site-packages/django/http/multipartparser.py", line 13, in <module>\n    from django.utils.text import unescape_entities
[Sun Mar 28 15:15:02 2010] [error] [client 137.112.132.137]   File "/usr/lib/python2.5/site-packages/django/utils/text.py", line 4, in <module>\n    from django.utils.translation import ugettext_lazy
[Sun Mar 28 15:15:02 2010] [error] [client 137.112.132.137]   File "/usr/lib/python2.5/site-packages/django/utils/translation/__init__.py", line 7, in <module>\n    from django.utils.translation import trans_real, trans_null
[Sun Mar 28 15:15:02 2010] [error] [client 137.112.132.137]   File "/usr/lib/python2.5/site-packages/django/utils/translation/trans_null.py", line 27, in <module>\n    "DATE_WITH_TIME_FULL": settings.DATETIME_FORMAT,
[Sun Mar 28 15:15:02 2010] [error] [client 137.112.132.137]   File "/usr/lib/python2.5/site-packages/django/utils/functional.py", line 281, in __getattr__\n    self._setup()
[Sun Mar 28 15:15:02 2010] [error] [client 137.112.132.137]   File "/usr/lib/python2.5/site-packages/django/conf/__init__.py", line 38, in _setup\n    raise ImportError("Settings cannot be imported, because environment variable %s is undefined." % ENVIRONMENT_VARIABLE)
[Sun Mar 28 15:15:02 2010] [error] [client 137.112.132.137] ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.

comment:5 Changed 4 years ago by russellm

By way of experimentation; can you try editing django/utils/translation/init.py, and moving line 4 (the call to "from django.conf import settings" to line 31 (i.e. - make the import of settings the first statement in delayed_loader, rather than a module level import)?

comment:6 Changed 4 years ago by anonymous

[Sun Mar 28 22:35:30 2010] [error] [client 137.112.132.137] Traceback (most recent call last):
[Sun Mar 28 22:35:30 2010] [error] [client 137.112.132.137]   File "/usr/lib/python2.5/site-packages/mod_python/importer.py", line 1537, in HandlerDispatch\n    default=default_handler, arg=req, silent=hlist.silent)
[Sun Mar 28 22:35:30 2010] [error] [client 137.112.132.137]   File "/usr/lib/python2.5/site-packages/mod_python/importer.py", line 1202, in _process_target\n    module = import_module(module_name, path=path)
[Sun Mar 28 22:35:30 2010] [error] [client 137.112.132.137]   File "/usr/lib/python2.5/site-packages/mod_python/importer.py", line 304, in import_module\n    return __import__(module_name, {}, {}, ['*'])
[Sun Mar 28 22:35:30 2010] [error] [client 137.112.132.137]   File "/usr/lib/python2.5/site-packages/django/core/handlers/modpython.py", line 4, in <module>\n    from django import http
[Sun Mar 28 22:35:30 2010] [error] [client 137.112.132.137]   File "/usr/lib/python2.5/site-packages/django/http/__init__.py", line 15, in <module>\n    from django.http.multipartparser import MultiPartParser
[Sun Mar 28 22:35:30 2010] [error] [client 137.112.132.137]   File "/usr/lib/python2.5/site-packages/django/http/multipartparser.py", line 13, in <module>\n    from django.utils.text import unescape_entities
[Sun Mar 28 22:35:30 2010] [error] [client 137.112.132.137]   File "/usr/lib/python2.5/site-packages/django/utils/text.py", line 4, in <module>\n    from django.utils.translation import ugettext_lazy
[Sun Mar 28 22:35:30 2010] [error] [client 137.112.132.137]   File "translation/__init__.py", line 6, in <module>
[Sun Mar 28 22:35:30 2010] [error] [client 137.112.132.137]   File "/usr/lib/python2.5/site-packages/django/utils/translation/trans_null.py", line 27, in <module>\n    "DATE_WITH_TIME_FULL": settings.DATETIME_FORMAT,
[Sun Mar 28 22:35:30 2010] [error] [client 137.112.132.137]   File "/usr/lib/python2.5/site-packages/django/utils/functional.py", line 281, in __getattr__\n    self._setup()
[Sun Mar 28 22:35:30 2010] [error] [client 137.112.132.137]   File "/usr/lib/python2.5/site-packages/django/conf/__init__.py", line 38, in _setup\n    raise ImportError("Settings cannot be imported, because environment variable %s is undefined." % ENVIRONMENT_VARIABLE)
[Sun Mar 28 22:35:30 2010] [error] [client 137.112.132.137] ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.

comment:7 Changed 4 years ago by Alex

How about if you move the import of trans_null and trans_real into the function?

comment:8 Changed 4 years ago by anonymous

Alex is a genius! That did it.

Index: django/utils/translation/__init__.py
===================================================================
--- django/utils/translation/__init__.py	(revision 12873)
+++ django/utils/translation/__init__.py	(working copy)
@@ -4,7 +4,6 @@
 from django.conf import settings
 from django.utils.encoding import force_unicode
 from django.utils.functional import lazy, curry
-from django.utils.translation import trans_real, trans_null
 
 
 __all__ = ['gettext', 'gettext_noop', 'gettext_lazy', 'ngettext',
@@ -28,6 +27,7 @@
     that modules can use the translation bits without actually requiring
     Django's settings bits to be configured before import.
     """
+    from django.utils.translation import trans_real, trans_null
     if settings.USE_I18N:
         trans = trans_real
     else:

comment:9 Changed 4 years ago by russellm

  • Component changed from django-admin.py runserver to Internationalization
  • milestone set to 1.2
  • Triage Stage changed from Unreviewed to Accepted

comment:10 Changed 4 years ago by russellm

  • Resolution set to fixed
  • Status changed from new to closed

(In [12875]) Fixed #13234 -- Rejiggered the imports in the translation utils . Thanks to roklenardic and Spark23 for their reports, and to Alex for his suggestion on a potential fix.

comment:11 Changed 3 years ago by jacob

  • milestone 1.2 deleted

Milestone 1.2 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.