Opened 17 years ago

Closed 17 years ago

#7387 closed (fixed)

Recursive imports in django.contrib.contenttypes.generic

Reported by: oliver@… Owned by: nobody
Component: Contrib apps Version: dev
Severity: Keywords: import importerror recursive contenttypes
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I'm trying to import django.contrib.contenttypes.generic in a script of mine, which causes a recursive import in Django:-

>>> from django.contrib.contenttypes import generic
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Python/2.5/site-packages/django/contrib/contenttypes/generic.py", line 8, in <module>
    from django.db.models import signals
  File "/Library/Python/2.5/site-packages/django/db/models/__init__.py", line 6, in <module>
    from django.db.models.query import Q
  File "/Library/Python/2.5/site-packages/django/db/models/query.py", line 7, in <module>
    from django.db.models import signals, sql
  File "/Library/Python/2.5/site-packages/django/db/models/sql/__init__.py", line 2, in <module>
    from subqueries import *
  File "/Library/Python/2.5/site-packages/django/db/models/sql/subqueries.py", line 5, in <module>
    from django.contrib.contenttypes import generic
ImportError: cannot import name generic

However, if I try this in Django's shell (as in through manage.py shell this seems to work fine for some reason. However, in a standard Python shell when I've run setup_environ it doesn't, and I see this error. It's important for me to be able to use it in the standard Python shell as this was highlighted to me by a script I'm trying to write).

Change History (4)

comment:1 by oliver@…, 17 years ago

Summary: Recursive imports in django.contib.contenttypes.genericRecursive imports in django.contrib.contenttypes.generic

comment:2 by George Vilches, 17 years ago

By coincidence I had the exact same error occur today. For a short term fix, do the imports in this order:

from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic

I'm not saying you should have to, just that it seems to work for setup_environ() for me.

comment:3 by Jeff Anderson, 17 years ago

Triage Stage: UnreviewedAccepted

comment:4 by Gary Wilson, 17 years ago

Resolution: fixed
Status: newclosed

(In [7635]) Fixed #7387 - Fixed circular import problem when importing contrib.contenttypes.generic module.

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