Opened 14 years ago

Closed 14 years ago

#7684 closed (invalid)

ugettext() in app `` causes error.

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


*Please note*: I know this may look like it belongs to the user mailing list, but in [1] we thought Trac would be a better place for it.

I'm having a strange import issue since I have upgraded my project to NFA. To illustrate the issue I've attached a ZIP with very simple code.

Basically, the project won't run (that is, when the server is restarted and tries to launch Django). I get the error: "ImportError: cannot import name MenuItem".

Now, what is very strange here, is that I can get rid of the error in two different ways:

1) Either by swapping the order of the apps in INSTALLED_APPS:





2) Or by Removing the ugettext call in menu.models:


caption = models.CharField(_('Caption'), max_length=50)


caption = models.CharField('Caption', max_length=50)

Weird! Does that example uncover a bug in Django or rather my misuse of Python and/or NFA?

I'm using newforms-admin-SVN-7871.


Attachments (1) (2.6 KB) - added by Julien Phalip 14 years ago.
Simple code illustrating the problem

Download all attachments as: .zip

Change History (6)

Changed 14 years ago by Julien Phalip

Attachment: added

Simple code illustrating the problem

comment:1 Changed 14 years ago by Brian Rosner

Resolution: invalid
Status: newclosed

I don't know the exact reason, but you should never use ugettext at module level, but rather ugettext_lazy. It does fix the problem. Probably due to some odd importing that it might impose by forcing the string translation at module loading time.

comment:2 Changed 14 years ago by Malcolm Tredinnick

Component: UncategorizedInternationalization
Resolution: invalid
Status: closedreopened
Triage Stage: UnreviewedAccepted

Reopening and assigning to i18n then (as a very low priority item). I want to understand this problem more if that's the problem. Fatal issues like this are something we should avoid, if possible (or document if not).

For anybody wanting to work on this (and it isn't blindingly urgent): what I'm interested in understanding is why using ugettext() is causing a failure. The only thing I can think of off the top of my head is having to do imports to search for locale directories or something, but that doesn't sound likely.

comment:3 Changed 14 years ago by Malcolm Tredinnick

Summary: Strange import problem since upgrading to newforms-adminugettext() in app `` causes error.

(Changed title to reflect probable problem.)

comment:4 Changed 14 years ago by Brian Rosner

Fair enough :) I wonder if the app's import of the local admin module might be causing this to go around like this. That convention is going away very soon with the fix of #6003.

comment:5 Changed 14 years ago by Julien Phalip

Resolution: invalid
Status: reopenedclosed

As noted by brosner, I was having that issue because the admin module was imported in the
Using the new recommended practice (e.g. autodiscover) removes that issue, so I'm now closing this ticket. As also noted by brosner above, ugettext_lazy should be used instead of ugettext in models declarations.

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