Hi Russel, > 2) I have seen the behaviour from r1796 before - for me, the problem > ultimately turned out to be caused by a PYTHONPATH that included the > application directory (so "from myapp.models import Foo" and "from > myproject.myapp.models import Foo" were both legal). At the time, I > chalked it up to the pythonpath, and moved on (sorry - can't give any > more specific details as to SVN revision, exact code structure, etc).
I think this points right to the root cause of the issue. manage.py mangles the PYTHONPATH such that both "import myproject.models" as well as "import myapp.myproject.models" work. However, Python doesn't recognize that both statements refer to the same source file, so if you have both variants in your code, it will import the same module twice! Steps to reproduce: Create a project with a single app, and a module in the app which prints a message if it is imported: miraculix:~/test martina$ django-admin.py startproject proj miraculix:~/test martina$ cd proj miraculix:~/test/proj martina$ ./manage.py startapp app miraculix:~/test/proj martina$ echo 'print "in app.m"'>app/m.py Now, run it under manage.py: miraculix:~/test/proj martina$ ./manage.py shell Python 2.4.1 (#2, Mar 31 2005, 00:05:10) Type "copyright", "credits" or "license" for more information. IPython 0.7.0 -- An enhanced Interactive Python. ? -> Introduction to IPython's features. %magic -> Information about IPython's 'magic' % functions. help -> Python's own help system. object? -> Details about 'object'. ?object also works, ?? prints more. In [2]: import proj.app.m in app.m In [3]: import app.m in app.m In [4]: import app.m In [5]: app.m is proj.app.m Out[5]: False Line 2 and 3 show that both variants are accepted, and that python doesn't treat them to be identical (otherwise, line 3 wouldn't print "in app.m", as line 4 shows.) Line 5 furthermore shows that the modules aren't identical as well. Now let's run this without manage.py: miraculix:~/test/proj martina$ ipython Python 2.4.1 (#2, Mar 31 2005, 00:05:10) Type "copyright", "credits" or "license" for more information. IPython 0.7.0 -- An enhanced Interactive Python. ? -> Introduction to IPython's features. %magic -> Information about IPython's 'magic' % functions. help -> Python's own help system. object? -> Details about 'object'. ?object also works, ?? prints more. In [1]: import proj.app.m ------------------------------------------------------------------------ --- exceptions.ImportError Traceback (most recent call last) /Users/martina/test/proj/<ipython console> ImportError: No module named proj.app.m In [2]: import app.m in app.m In [3]: import app.m In [4]: In this case, only the variant "import app.m" is allowed, and no ambiguity arises. I think this ambiguity should be resolved. What's the reason that manage.py adds the current directory to the pythonpath? Could this be removed? One problem would be that this would break a lot of code that uses "import project.app..." ciao Martina --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-developers -~----------~----~----~----~------~----~------~--~---
