[Django] #22057: Importing `reverse_lazy` in settings.py leads to ImportError

45 views
Skip to first unread message

Django

unread,
Feb 15, 2014, 3:37:19 PM2/15/14
to django-...@googlegroups.com
#22057: Importing `reverse_lazy` in settings.py leads to ImportError
---------------------------------+--------------------
Reporter: dfunckt | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: master
Severity: Release blocker | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------
Create a new project, add an app with a model and import reverse_lazy in
settings.py. Running {{{./manage.py sqlall myapp}}} raises ImportError
with the following traceback:

{{{
$ ./manage.py sqlall myapp
Traceback (most recent call last):
File "<project>/settings.py", line 2, in <module>
from .settings_local import *
File "<project>/settings_local.py", line 1, in <module>
from .settings_base import *
File "<project>/settings_base.py", line 5, in <module>
from django.core.urlresolvers import reverse_lazy
File "<virtualenv>/src/django/django/core/urlresolvers.py", line 15, in
<module>
from django.http import Http404
File "<virtualenv>/src/django/django/http/__init__.py", line 4, in
<module>
from django.http.response import (HttpResponse, StreamingHttpResponse,
File "<virtualenv>/src/django/django/http/response.py", line 17, in
<module>
from django.core.serializers.json import DjangoJSONEncoder
File "<virtualenv>/src/django/django/core/serializers/__init__.py", line
23, in <module>
from django.core.serializers.base import SerializerDoesNotExist
File "<virtualenv>/src/django/django/core/serializers/base.py", line 6,
in <module>
from django.db import models
ImportError: cannot import name models
}}}

Marking as a release blocker as discussed with apollo13 in IRC.

Cause of this regression is commit:
https://github.com/django/django/commit/0242134d32aa99a54442211ed05576b7061866d1

--
Ticket URL: <https://code.djangoproject.com/ticket/22057>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Feb 15, 2014, 3:38:10 PM2/15/14
to django-...@googlegroups.com
#22057: Importing `reverse_lazy` in settings.py leads to ImportError
---------------------------------+------------------------------------

Reporter: dfunckt | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: master
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by dfunckt):

* needs_better_patch: => 0
* needs_docs: => 0
* needs_tests: => 0
* stage: Unreviewed => Accepted


Comment:

Marking as accepted as discussed with apollo13

--
Ticket URL: <https://code.djangoproject.com/ticket/22057#comment:1>

Django

unread,
Feb 16, 2014, 6:10:55 AM2/16/14
to django-...@googlegroups.com
#22057: Importing `reverse_lazy` in settings.py leads to ImportError
---------------------------------+------------------------------------

Reporter: dfunckt | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: master
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------

Comment (by gnosek):

Cannot reproduce even though there is a clear circular import. Does
anybody have a self-contained app showing the problem?

--
Ticket URL: <https://code.djangoproject.com/ticket/22057#comment:2>

Django

unread,
Feb 16, 2014, 6:35:08 AM2/16/14
to django-...@googlegroups.com
#22057: Importing `reverse_lazy` in settings.py leads to ImportError
---------------------------------+------------------------------------

Reporter: dfunckt | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: master
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------

Comment (by dfunckt):

I attached a test project. Using Django@master, Python 3.3.

--
Ticket URL: <https://code.djangoproject.com/ticket/22057#comment:3>

Django

unread,
Feb 16, 2014, 7:06:54 AM2/16/14
to django-...@googlegroups.com
#22057: Importing `reverse_lazy` in settings.py leads to ImportError
---------------------------------+------------------------------------

Reporter: dfunckt | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: master
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------

Comment (by dfunckt):

Added a quick patch that fixes the issue. Run tests with sqlite, all pass.

--
Ticket URL: <https://code.djangoproject.com/ticket/22057#comment:4>

Django

unread,
Feb 16, 2014, 7:53:05 AM2/16/14
to django-...@googlegroups.com
#22057: Importing `reverse_lazy` in settings.py leads to ImportError
---------------------------------+------------------------------------

Reporter: dfunckt | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: master
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------

Comment (by anonymous):

I think it's better to just move the !DjangoJSONEncoder into the
JSONResponse

--
Ticket URL: <https://code.djangoproject.com/ticket/22057#comment:5>

Django

unread,
Feb 16, 2014, 10:17:43 AM2/16/14
to django-...@googlegroups.com
#22057: Importing `reverse_lazy` in settings.py leads to ImportError
---------------------------------+------------------------------------

Reporter: dfunckt | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: master
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------

Comment (by dfunckt):

Added another patch, fixing the issue by lazily importing
{{{DjangoJSONEncoder}}} inside {{{JSONResponse.__init__}}}.

I'm not sure how to go about testing for this regression in order to
provide a complete patch, so if anyone has any pointers it would help.

--
Ticket URL: <https://code.djangoproject.com/ticket/22057#comment:6>

Django

unread,
Feb 16, 2014, 12:19:38 PM2/16/14
to django-...@googlegroups.com
#22057: Importing `reverse_lazy` in settings.py leads to ImportError
---------------------------------+------------------------------------

Reporter: dfunckt | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: master
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------

Comment (by aaugustin):

Such patches are fragile. We try to keep imports properly ordered at the
top of modules. After a few years it becomes unclear why a specific import
doesn't happen at module level, and if it's still needed.

--
Ticket URL: <https://code.djangoproject.com/ticket/22057#comment:7>

Django

unread,
Feb 16, 2014, 3:58:18 PM2/16/14
to django-...@googlegroups.com
#22057: Importing `reverse_lazy` in settings.py leads to ImportError
---------------------------------+------------------------------------

Reporter: dfunckt | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: master
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------

Comment (by claudep):

I think the problem is caused by two lines here:
https://github.com/django/django/blob/master/django/db/models/sql/aggregates.py#L14-15

It shouldn't be too difficult to defer these instanciations. I'll attach a
patch.

--
Ticket URL: <https://code.djangoproject.com/ticket/22057#comment:8>

Django

unread,
Feb 18, 2014, 5:10:55 AM2/18/14
to django-...@googlegroups.com
#22057: Importing `reverse_lazy` in settings.py leads to ImportError
---------------------------------+------------------------------------
Reporter: dfunckt | Owner: nobody
Type: Bug | Status: closed
Component: Uncategorized | Version: master
Severity: Release blocker | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by Claude Paroz <claude@…>):

* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"45edb9d2359c60952fd791616df887eb95f75746"]:
{{{
#!CommitTicketReference repository=""
revision="45edb9d2359c60952fd791616df887eb95f75746"
Fixed #22057 -- Ensured reverse_lazy can be used in settings

And without causing a circular import. Thanks Akis Kesoglou for
the report.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/22057#comment:9>

Reply all
Reply to author
Forward
0 new messages