Opened 8 years ago

Closed 8 years ago

#7684 closed (invalid)

ugettext() in app `` causes error.

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


*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 8 years ago.
Simple code illustrating the problem

Download all attachments as: .zip

Change History (6)

Changed 8 years ago by julien

Simple code illustrating the problem

comment:1 Changed 8 years ago by brosner

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

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 8 years ago by mtredinnick

  • Component changed from Uncategorized to Internationalization
  • Resolution invalid deleted
  • Status changed from closed to reopened
  • Triage Stage changed from Unreviewed to Accepted

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 8 years ago by mtredinnick

  • Summary changed from Strange import problem since upgrading to newforms-admin to ugettext() in app `` causes error.

(Changed title to reflect probable problem.)

comment:4 Changed 8 years ago by brosner

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 8 years ago by julien

  • Resolution set to invalid
  • Status changed from reopened to closed

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