#22699 closed Bug (fixed)
app registry error when running startproject with a template containing DATE_FORMAT
Reported by: | jarshwah | Owned by: | Aymeric Augustin |
---|---|---|---|
Component: | Core (Management commands) | Version: | 1.7-beta-2 |
Severity: | Release blocker | Keywords: | app-loading management-commands |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Repro:
django-admin startproject --template=template/ fail
Where template/project.py contains:
{% now "DATE_FORMAT" %}
And the traceback:
Traceback (most recent call last): File "/usr/local/bin/django-admin", line 9, in <module> load_entry_point('Django==1.7b4', 'console_scripts', 'django-admin')() File "/usr/local/lib/python3.4/site-packages/django/core/management/__init__.py", line 427, in execute_from_command_line utility.execute() File "/usr/local/lib/python3.4/site-packages/django/core/management/__init__.py", line 419, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/usr/local/lib/python3.4/site-packages/django/core/management/base.py", line 288, in run_from_argv self.execute(*args, **options.__dict__) File "/usr/local/lib/python3.4/site-packages/django/core/management/base.py", line 337, in execute output = self.handle(*args, **options) File "/usr/local/lib/python3.4/site-packages/django/core/management/commands/startproject.py", line 31, in handle super(Command, self).handle('project', project_name, target, **options) File "/usr/local/lib/python3.4/site-packages/django/core/management/templates.py", line 158, in handle content = template.render(context) File "/usr/local/lib/python3.4/site-packages/django/template/base.py", line 148, in render return self._render(context) File "/usr/local/lib/python3.4/site-packages/django/template/base.py", line 142, in _render return self.nodelist.render(context) File "/usr/local/lib/python3.4/site-packages/django/template/base.py", line 844, in render bit = self.render_node(node, context) File "/usr/local/lib/python3.4/site-packages/django/template/base.py", line 858, in render_node return node.render(context) File "/usr/local/lib/python3.4/site-packages/django/template/defaulttags.py", line 393, in render return date(datetime.now(tz=tzinfo), self.format_string) File "/usr/local/lib/python3.4/site-packages/django/template/defaultfilters.py", line 766, in date return formats.date_format(value, arg) File "/usr/local/lib/python3.4/site-packages/django/utils/formats.py", line 126, in date_format return dateformat.format(value, get_format(format or 'DATE_FORMAT', use_l10n=use_l10n)) File "/usr/local/lib/python3.4/site-packages/django/utils/dateformat.py", line 343, in format return df.format(format_string) File "/usr/local/lib/python3.4/site-packages/django/utils/dateformat.py", line 35, in format pieces.append(force_text(getattr(self, piece)())) File "/usr/local/lib/python3.4/site-packages/django/utils/encoding.py", line 83, in force_text s = six.text_type(s) File "/usr/local/lib/python3.4/site-packages/django/utils/functional.py", line 144, in __text_cast return func(*self.__args, **self.__kw) File "/usr/local/lib/python3.4/site-packages/django/utils/translation/__init__.py", line 91, in pgettext return _trans.pgettext(context, message) File "/usr/local/lib/python3.4/site-packages/django/utils/translation/trans_real.py", line 322, in pgettext result = ugettext(msg_with_ctxt) File "/usr/local/lib/python3.4/site-packages/django/utils/translation/trans_real.py", line 311, in gettext return do_translate(message, 'gettext') File "/usr/local/lib/python3.4/site-packages/django/utils/translation/trans_real.py", line 298, in do_translate _default = translation(settings.LANGUAGE_CODE) File "/usr/local/lib/python3.4/site-packages/django/utils/translation/trans_real.py", line 201, in translation default_translation = _fetch(settings.LANGUAGE_CODE) File "/usr/local/lib/python3.4/site-packages/django/utils/translation/trans_real.py", line 184, in _fetch for app_config in reversed(list(apps.get_app_configs())): File "/usr/local/lib/python3.4/site-packages/django/apps/registry.py", line 125, in get_app_configs self.check_ready() File "/usr/local/lib/python3.4/site-packages/django/apps/registry.py", line 119, in check_ready raise RuntimeError("App registry isn't ready yet.") RuntimeError: App registry isn't ready yet.
Sample template attached.
Attachments (1)
Change History (9)
by , 10 years ago
Attachment: | template.tar.gz added |
---|
comment:1 by , 10 years ago
Severity: | Normal → Release blocker |
---|---|
Triage Stage: | Unreviewed → Accepted |
Type: | Uncategorized → Bug |
comment:2 by , 10 years ago
What about configuring Django with the default settings (from global_settings.py) when no settings module is available?
comment:3 by , 10 years ago
Very interesting idea, indeed. That would give:
diff --git a/django/core/management/__init__.py b/django/core/management/__init__.py index df21ed9..00c1a1f 100644 --- a/django/core/management/__init__.py +++ b/django/core/management/__init__.py @@ -388,9 +388,10 @@ class ManagementUtility(object): settings.INSTALLED_APPS except ImproperlyConfigured: # Some commands are supposed to work without configured settings - pass - else: - django.setup() + # Use default settings instead + settings.configure() + + django.setup() self.autocomplete()
comment:4 by , 10 years ago
When I raised the bug I imagined the fix would look something like above (enabling default settings and calling setup()). If there are other lingering bugs that involve configuring django that does not use translations, you'd be in trouble with the first patch that only disables translations.
comment:5 by , 10 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
Claude, that's the kind of change I imagined. I'll have a bit more time to think about it and commit it tomorrow. Thanks for your help.
comment:6 by , 10 years ago
Has patch: | set |
---|
PR: https://github.com/django/django/pull/2722
What do you think of this refactoring?
comment:7 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
DATE_FORMAT contains language-dependent elements, hence the failure because the translation infrastructure cannot be used without configured settings (which startproject cannot obviously provide).
One possible fix would be to deactivate translations when the management command infrastructure detects settings are not available: