Opened 14 years ago

Closed 14 years ago

Last modified 13 years ago

#13234 closed (fixed)

cannot import name trans_real

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

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?

Change History (11)

comment:1 by Alex Gaynor, 14 years ago

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 by Jannis Leidel, 14 years ago

Cc: Jannis Leidel added

comment:3 by Karen Tracey, 14 years ago

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 by anonymous, 14 years ago

[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 by Russell Keith-Magee, 14 years ago

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 by anonymous, 14 years ago

[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 by Alex Gaynor, 14 years ago

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

comment:8 by anonymous, 14 years ago

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 by Russell Keith-Magee, 14 years ago

Component: django-admin.py runserverInternationalization
milestone: 1.2
Triage Stage: UnreviewedAccepted

comment:10 by Russell Keith-Magee, 14 years ago

Resolution: fixed
Status: newclosed

(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 by Jacob, 13 years ago

milestone: 1.2

Milestone 1.2 deleted

Note: See TracTickets for help on using tickets.
Back to Top