Opened 16 years ago

Last modified 14 years ago

#8011 closed

Translated strings in a ForeignKey of a model in an application not in the project root causes errors — at Version 2

Reported by: anonymous Owned by: Malcolm Tredinnick
Component: Translations Version: dev
Severity: Keywords: translation, lazy, model
Cc: oliver@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Malcolm Tredinnick)

This seems like a real edge-case, but still it is an issue (for me at least). Since the memory optimization stuff from [8127], if I have a lazily translated string (in this case as the verbose_name) for a ForeignKey, which is in a model located in an application not in the project root (in this case in project.generic.tagging, I get this lovely error:

Traceback (most recent call last):
  File "manage.py", line 11, in <module>
    execute_manager(settings)
  File "/usr/local/obeattie/__init__.py", line 301, in execute_manager
    
  File "/usr/local/obeattie/__init__.py", line 248, in execute
    
  File "/sw/lib/python2.5/site-packages/django/core/management/base.py", line 77, in run_from_argv
  File "/sw/lib/python2.5/site-packages/django/core/management/base.py", line 86, in execute
  File "/usr/local/django/trunk/django/utils/translation/__init__.py", line 73, in activate
    return real_activate(language)
  File "/usr/local/django/trunk/django/utils/translation/__init__.py", line 43, in delayed_loader
    return g['real_%s' % caller](*args, **kwargs)
  File "/Library/Python/2.5/site-packages/django/utils/translation/trans_real.py", line 209, in activate
    _active[currentThread()] = translation(language)
  File "/Library/Python/2.5/site-packages/django/utils/translation/trans_real.py", line 198, in translation
    default_translation = _fetch(settings.LANGUAGE_CODE)
  File "/Library/Python/2.5/site-packages/django/utils/translation/trans_real.py", line 181, in _fetch
    app = getattr(__import__(appname[:p], {}, {}, [appname[p+1:]]), appname[p+1:])
  File "/usr/local/obeattie/../obeattie/generic/tagging/__init__.py", line 1, in <module>
    import obeattie.generic.tagging.admin
  File "/usr/local/obeattie/../obeattie/generic/tagging/admin.py", line 3, in <module>
    from obeattie.generic.tagging import models as tagging_models
  File "/usr/local/obeattie/../obeattie/generic/tagging/models.py", line 500, in <module>
    class TaggedItem(models.Model):
  File "/Library/Python/2.5/site-packages/django/db/models/base.py", line 89, in __new__
    new_class.add_to_class(obj_name, obj)
  File "/Library/Python/2.5/site-packages/django/db/models/base.py", line 140, in add_to_class
    value.contribute_to_class(cls, name)
  File "/Library/Python/2.5/site-packages/django/db/models/fields/related.py", line 672, in contribute_to_class
    super(ForeignKey, self).contribute_to_class(cls, name)
  File "/Library/Python/2.5/site-packages/django/db/models/fields/related.py", line 113, in contribute_to_class
    self.do_related_class(other, cls)
  File "/Library/Python/2.5/site-packages/django/db/models/fields/related.py", line 121, in do_related_class
    self.set_attributes_from_rel()
  File "/Library/Python/2.5/site-packages/django/db/models/fields/related.py", line 117, in set_attributes_from_rel
    self.verbose_name = self.verbose_name or self.rel.to._meta.verbose_name
  File "/Library/Python/2.5/site-packages/django/utils/functional.py", line 188, in __wrapper__
    res = self.__func(*self.__args, **self.__kw)
  File "/usr/local/django/trunk/django/utils/translation/__init__.py", line 62, in ugettext
    return real_ugettext(message)
  File "/Library/Python/2.5/site-packages/django/utils/translation/trans_real.py", line 288, in ugettext
    return do_translate(message, 'ugettext')
  File "/Library/Python/2.5/site-packages/django/utils/translation/trans_real.py", line 278, in do_translate
    _default = translation(settings.LANGUAGE_CODE)
  File "/Library/Python/2.5/site-packages/django/utils/translation/trans_real.py", line 198, in translation
    default_translation = _fetch(settings.LANGUAGE_CODE)
  File "/Library/Python/2.5/site-packages/django/utils/translation/trans_real.py", line 181, in _fetch
    app = getattr(__import__(appname[:p], {}, {}, [appname[p+1:]]), appname[p+1:])
AttributeError: 'module' object has no attribute 'tagging'

(This actually happened in django-tagging). I've tracked it down to changes made to or in django.utils.functional.lazy.__proxy__.__promise__.__wrapper__ — it doesn't appear that it got called prior to these changes (in [8119] at least), if that helps at all.

Change History (2)

comment:1 by oliver@…, 16 years ago

Cc: oliver@… added

Damn, I reported this as anonymous. Adding myself to the Cc.

comment:2 by Malcolm Tredinnick, 16 years ago

Description: modified (diff)
Owner: changed from nobody to Malcolm Tredinnick
Triage Stage: UnreviewedAccepted

Thanks for the report. There are no edge cases in this are -- they're all real bugs.

The "problem" is that we're now copying all of the methods from the underlying function return value to the lazy object, so even things like bool() (e.g. if self.verbose_name:...) end up triggering a translation and that's a bad thing to do whilst the apps are loading. I'll hook up a quick hack to fix this and investigate a longer term solution when I get a chance.

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