Opened 17 years ago

Closed 17 years ago

Last modified 17 years ago

#5389 closed (invalid)

ImportError in daily_cleanup.py after [6087] changeset

Reported by: Boo <boobsd@…> Owned by: Adrian Holovaty
Component: Database layer (models, ORM) Version: dev
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Settings:

INSTALLED_APPS = (
...
    'corpsite.feedagregator',
)

Traceback:

Traceback (most recent call last):
  File "daily_cleanup.py", line 20, in ?
    clean_up()
  File "daily_cleanup.py", line 16, in clean_up
    Session.objects.filter(expire_date__lt=datetime.datetime.now()).delete()
  File "/usr/local/lib/python2.4/site-packages/django/db/models/query.py", line 342, in delete
    for object in del_query[0:GET_ITERATOR_CHUNK_SIZE]:
  File "/usr/local/lib/python2.4/site-packages/django/db/models/query.py", line 114, in __iter__
    return iter(self._get_data())
  File "/usr/local/lib/python2.4/site-packages/django/db/models/query.py", line 482, in _get_data
    self._result_cache = list(self.iterator())
  File "/usr/local/lib/python2.4/site-packages/django/db/models/query.py", line 180, in iterator
    select, sql, params = self._get_sql_clause()
  File "/usr/local/lib/python2.4/site-packages/django/db/models/query.py", line 497, in _get_sql_clause
    joins2, where2, params2 = self._filters.get_sql(opts)
  File "/usr/local/lib/python2.4/site-packages/django/db/models/query.py", line 719, in get_sql
    joins2, where2, params2 = val.get_sql(opts)
  File "/usr/local/lib/python2.4/site-packages/django/db/models/query.py", line 770, in get_sql
    return parse_lookup(self.kwargs.items(), opts)
  File "/usr/local/lib/python2.4/site-packages/django/db/models/query.py", line 922, in parse_lookup
    joins2, where2, params2 = lookup_inner(path, lookup_type, value, opts, opts.db_table, None)
  File "/usr/local/lib/python2.4/site-packages/django/db/models/query.py", line 987, in lookup_inner
    field = find_field(name, current_opts.get_all_related_many_to_many_objects(), True)
  File "/usr/local/lib/python2.4/site-packages/django/db/models/options.py", line 177, in get_all_related_many_to_many_objects
    for klass in get_models():
  File "/usr/local/lib/python2.4/site-packages/django/db/models/loading.py", line 134, in get_models
    self._populate()
  File "/usr/local/lib/python2.4/site-packages/django/db/models/loading.py", line 55, in _populate
    self.load_app(app_name, True)
  File "/usr/local/lib/python2.4/site-packages/django/db/models/loading.py", line 70, in load_app
    mod = __import__(app_name, {}, {}, ['models'])
ImportError: No module named corpsite.feedagregator

Change History (17)

comment:1 by Adrian Holovaty, 17 years ago

Resolution: worksforme
Status: newclosed

Are you sure 'corpsite.feedagregator' isn't misspelled? The correct way to spell it is feedaggregator.

comment:2 by Boo <boobsd@…>, 17 years ago

Resolution: worksforme
Status: closedreopened

i'm sure, cause before [6087] it worked right:

[root@boo ~/projects/corpsite]# ./manage.py --version
0.97-pre-SVN-6095
[root@boo ~/projects/corpsite]# ./daily_cleanup.py 
Traceback (most recent call last):
  File "./daily_cleanup.py", line 20, in ?
    clean_up()
  File "./daily_cleanup.py", line 16, in clean_up
    Session.objects.filter(expire_date__lt=datetime.datetime.now()).delete()
  File "/usr/local/lib/python2.4/site-packages/django/db/models/query.py", line 342, in delete
    for object in del_query[0:GET_ITERATOR_CHUNK_SIZE]:
  File "/usr/local/lib/python2.4/site-packages/django/db/models/query.py", line 114, in __iter__
    return iter(self._get_data())
  File "/usr/local/lib/python2.4/site-packages/django/db/models/query.py", line 482, in _get_data
    self._result_cache = list(self.iterator())
  File "/usr/local/lib/python2.4/site-packages/django/db/models/query.py", line 180, in iterator
    select, sql, params = self._get_sql_clause()
  File "/usr/local/lib/python2.4/site-packages/django/db/models/query.py", line 497, in _get_sql_clause
    joins2, where2, params2 = self._filters.get_sql(opts)
  File "/usr/local/lib/python2.4/site-packages/django/db/models/query.py", line 719, in get_sql
    joins2, where2, params2 = val.get_sql(opts)
  File "/usr/local/lib/python2.4/site-packages/django/db/models/query.py", line 770, in get_sql
    return parse_lookup(self.kwargs.items(), opts)
  File "/usr/local/lib/python2.4/site-packages/django/db/models/query.py", line 922, in parse_lookup
    joins2, where2, params2 = lookup_inner(path, lookup_type, value, opts, opts.db_table, None)
  File "/usr/local/lib/python2.4/site-packages/django/db/models/query.py", line 987, in lookup_inner
    field = find_field(name, current_opts.get_all_related_many_to_many_objects(), True)
  File "/usr/local/lib/python2.4/site-packages/django/db/models/options.py", line 177, in get_all_related_many_to_many_objects
    for klass in get_models():
  File "/usr/local/lib/python2.4/site-packages/django/db/models/loading.py", line 134, in get_models
    self._populate()
  File "/usr/local/lib/python2.4/site-packages/django/db/models/loading.py", line 55, in _populate
    self.load_app(app_name, True)
  File "/usr/local/lib/python2.4/site-packages/django/db/models/loading.py", line 70, in load_app
    mod = __import__(app_name, {}, {}, ['models'])
ImportError: No module named corpsite.benefits
[root@boo ~/projects/corpsite]# cd /usr/local/src/django
[root@boo /usr/local/src/django]# svn up -r 6086
U    django/db/models/loading.py
U    django/core/management/base.py
U    django/core/management/commands/runfcgi.py
U    django/core/management/__init__.py
U    tests/regressiontests/forms/regressions.py
Updated to revision 6086.
[root@boo /usr/local/src/django]# cd ~/projects/corpsite
[root@boo ~/projects/corpsite]# ./daily_cleanup.py 
[root@boo ~/projects/corpsite]# ./daily_cleanup.py 
[root@boo ~/projects/corpsite]#

comment:3 by alexander.pugachev@…, 17 years ago

I updated my SVN work copy of Django. Then created new clean project. Started there new application.
Changed settings.py to connect the project to database and added my application to list of installed applications. Copied daily.py to root of project and exported DJANGO_SETINGS_MODULE.
Then I was able to import module called "ticket.correct" in Django shell, and was no able to run daily_update.py. I did not misspelled any words?

~/test$ django-admin.py startproject ticket
~/test$ cd ticket/
~/test/ticket$ ./manage.py --version
0.97-pre-SVN-6095
~/test/ticket$ ./manage.py startapp correct
~/test/ticket$ vim settings.py
{{{INSTALLED_APPS = (

'django.contrib.auth',

...

'ticket.correct'

)}}}
~/test/ticket$ ls
correct init.py manage.py settings.pyc
daily_cleanup.py init.pyc settings.py urls.py
~/test/ticket$ ./daily_cleanup.py
Traceback (most recent call last):

File "./daily_cleanup.py", line 20, in <module>

clean_up()

File "./daily_cleanup.py", line 16, in clean_up

Session.objects.filter(expire_datelt=datetime.datetime.now()).delete()

File "/usr/local/lib/python2.5/site-packages/django/db/models/query.py", line 342, in delete

for object in del_query[0:GET_ITERATOR_CHUNK_SIZE]:

File "/usr/local/lib/python2.5/site-packages/django/db/models/query.py", line 114, in iter

return iter(self._get_data())

File "/usr/local/lib/python2.5/site-packages/django/db/models/query.py", line 482, in _get_data

self._result_cache = list(self.iterator())

File "/usr/local/lib/python2.5/site-packages/django/db/models/query.py", line 180, in iterator

select, sql, params = self._get_sql_clause()

File "/usr/local/lib/python2.5/site-packages/django/db/models/query.py", line 497, in _get_sql_clause

joins2, where2, params2 = self._filters.get_sql(opts)

File "/usr/local/lib/python2.5/site-packages/django/db/models/query.py", line 719, in get_sql

joins2, where2, params2 = val.get_sql(opts)

File "/usr/local/lib/python2.5/site-packages/django/db/models/query.py", line 770, in get_sql

return parse_lookup(self.kwargs.items(), opts)

File "/usr/local/lib/python2.5/site-packages/django/db/models/query.py", line 922, in parse_lookup

joins2, where2, params2 = lookup_inner(path, lookup_type, value, opts, opts.db_table, None)

File "/usr/local/lib/python2.5/site-packages/django/db/models/query.py", line 987, in lookup_inner

field = find_field(name, current_opts.get_all_related_many_to_many_objects(), True)

File "/usr/local/lib/python2.5/site-packages/django/db/models/options.py", line 177, in get_all_related_many_to_many_objects

for klass in get_models():

File "/usr/local/lib/python2.5/site-packages/django/db/models/loading.py", line 134, in get_models

self._populate()

File "/usr/local/lib/python2.5/site-packages/django/db/models/loading.py", line 55, in _populate

self.load_app(app_name, True)

File "/usr/local/lib/python2.5/site-packages/django/db/models/loading.py", line 70, in load_app

mod = import(app_name, {}, {}, models)

ImportError: No module named ticket.correct
~/test/ticket$ ./manage.py shell
Python 2.5.1 (r251:54863, May 2 2007, 16:56:35)
[GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)

import ticket.correct
dir(ticket.correct)

['builtins', 'doc', 'file', 'name', 'path', 'models']

comment:4 by rokclimb15@…, 17 years ago

Component: UncategorizedDatabase wrapper

I am also experiencing this problem in an external loading script (loading initial data with ORM) after revision 6087. Reverting my SVN checkout to 6086 does not produce the problem.

brian@brian-desktop:/djangosites/btevents$ python migratesongs.py 
Traceback (most recent call last):
  File "migratesongs.py", line 49, in <module>
    song_exists = Song.objects.filter(title=song_name, artists__name__exact=artist, categories__name__exact=category).count()
  File "/usr/lib/python2.5/site-packages/django/db/models/query.py", line 233, in count
    select, sql, params = counter._get_sql_clause()
  File "/usr/lib/python2.5/site-packages/django/db/models/query.py", line 497, in _get_sql_clause
    joins2, where2, params2 = self._filters.get_sql(opts)
  File "/usr/lib/python2.5/site-packages/django/db/models/query.py", line 719, in get_sql
    joins2, where2, params2 = val.get_sql(opts)
  File "/usr/lib/python2.5/site-packages/django/db/models/query.py", line 770, in get_sql
    return parse_lookup(self.kwargs.items(), opts)
  File "/usr/lib/python2.5/site-packages/django/db/models/query.py", line 922, in parse_lookup
    joins2, where2, params2 = lookup_inner(path, lookup_type, value, opts, opts.db_table, None)
  File "/usr/lib/python2.5/site-packages/django/db/models/query.py", line 1072, in lookup_inner
    joins2, where2, params2 = lookup_inner(path, lookup_type, value, new_opts, new_table, join_column)
  File "/usr/lib/python2.5/site-packages/django/db/models/query.py", line 987, in lookup_inner
    field = find_field(name, current_opts.get_all_related_many_to_many_objects(), True)
  File "/usr/lib/python2.5/site-packages/django/db/models/options.py", line 177, in get_all_related_many_to_many_objects
    for klass in get_models():
  File "/usr/lib/python2.5/site-packages/django/db/models/loading.py", line 134, in get_models
    self._populate()
  File "/usr/lib/python2.5/site-packages/django/db/models/loading.py", line 55, in _populate
    self.load_app(app_name, True)
  File "/usr/lib/python2.5/site-packages/django/db/models/loading.py", line 70, in load_app
    mod = __import__(app_name, {}, {}, ['models'])
ImportError: No module named btevents.web

comment:5 by Simon G. <dev@…>, 17 years ago

Triage Stage: UnreviewedAccepted

comment:6 by Allagappan (IRC:vegpuff), 17 years ago

Owner: changed from nobody to Allagappan (IRC:vegpuff)
Status: reopenednew

comment:7 by Allagappan (IRC:vegpuff), 17 years ago

Owner: changed from Allagappan (IRC:vegpuff) to nobody

comment:8 by Ville Säävuori, 17 years ago

I cannot duplicate this with current Django revision ( 6186 ).

in reply to:  8 comment:9 by Artem Gnilov <boobsd@…>, 17 years ago

Replying to Uninen:

I cannot duplicate this with current Django revision ( 6186 ).

[root@boo ~/projects/corpsite]# ./manage.py --version
0.97-pre-SVN-6186
[root@boo ~/projects/corpsite]# ./daily_cleanup.py 
Traceback (most recent call last):
  File "./daily_cleanup.py", line 20, in ?
    clean_up()
  File "./daily_cleanup.py", line 16, in clean_up
    Session.objects.filter(expire_date__lt=datetime.datetime.now()).delete()
  File "/usr/local/lib/python2.4/site-packages/django/db/models/query.py", line 342, in delete
    for object in del_query[0:GET_ITERATOR_CHUNK_SIZE]:
  File "/usr/local/lib/python2.4/site-packages/django/db/models/query.py", line 114, in __iter__
    return iter(self._get_data())
  File "/usr/local/lib/python2.4/site-packages/django/db/models/query.py", line 482, in _get_data
    self._result_cache = list(self.iterator())
  File "/usr/local/lib/python2.4/site-packages/django/db/models/query.py", line 180, in iterator
    select, sql, params = self._get_sql_clause()
  File "/usr/local/lib/python2.4/site-packages/django/db/models/query.py", line 497, in _get_sql_clause
    joins2, where2, params2 = self._filters.get_sql(opts)
  File "/usr/local/lib/python2.4/site-packages/django/db/models/query.py", line 719, in get_sql
    joins2, where2, params2 = val.get_sql(opts)
  File "/usr/local/lib/python2.4/site-packages/django/db/models/query.py", line 770, in get_sql
    return parse_lookup(self.kwargs.items(), opts)
  File "/usr/local/lib/python2.4/site-packages/django/db/models/query.py", line 922, in parse_lookup
    joins2, where2, params2 = lookup_inner(path, lookup_type, value, opts, opts.db_table, None)
  File "/usr/local/lib/python2.4/site-packages/django/db/models/query.py", line 987, in lookup_inner
    field = find_field(name, current_opts.get_all_related_many_to_many_objects(), True)
  File "/usr/local/lib/python2.4/site-packages/django/db/models/options.py", line 177, in get_all_related_many_to_many_objects
    for klass in get_models():
  File "/usr/local/lib/python2.4/site-packages/django/db/models/loading.py", line 134, in get_models
    self._populate()
  File "/usr/local/lib/python2.4/site-packages/django/db/models/loading.py", line 55, in _populate
    self.load_app(app_name, True)
  File "/usr/local/lib/python2.4/site-packages/django/db/models/loading.py", line 70, in load_app
    mod = __import__(app_name, {}, {}, ['models'])
ImportError: No module named corpsite.benefits

comment:10 by emperorcezar, 17 years ago

Owner: changed from nobody to emperorcezar

comment:11 by emperorcezar, 17 years ago

Resolution: invalid
Status: newclosed

This bug is caused by the user not having the python path setup correctly. Note that if you're using ./manage.py runserver that you will need to setup the PYTHONPATH separately to run daily_cleanup.py

Example

export PYTHONPATH=/home/user/project_name

This should allow you to just have 'app_name' in your INSTALLED_APPS when running python ./daily_cleanup.py

comment:12 by anonymous, 17 years ago

Resolution: invalid
Status: closedreopened

comment:13 by Fredrik Lundh <fredrik@…>, 17 years ago

Resolution: invalid
Status: reopenedclosed

A local configuration issue is not a bug. Please make sure that you've set the path correctly before reopening this ticket, and if you do reopen it, please explain why.

comment:14 by boobsd@…, 17 years ago

Resolution: invalid
Status: closedreopened

In http://www.djangoproject.com/documentation/tutorial01/ wrote:

INSTALLED_APPS = (
....
    'mysite.polls'
)

In settings of my testcase:

INSTALLED_APPS = (
....
    'mysite.myapp'
)

Shell:

[root@boo ~/projects/mysite]# ./manage.py --version
0.97-pre-SVN-6213
[root@boo ~/projects/mysite]# export DJANGO_SETTINGS_MODULE=settings
[root@boo ~/projects/mysite]# ./daily_cleanup.py 
Traceback (most recent call last):
  File "./daily_cleanup.py", line 20, in ?
    clean_up()
  File "./daily_cleanup.py", line 16, in clean_up
    Session.objects.filter(expire_date__lt=datetime.datetime.now()).delete()
  File "/usr/local/lib/python2.4/site-packages/django/db/models/query.py", line 342, in delete
    for object in del_query[0:GET_ITERATOR_CHUNK_SIZE]:
  File "/usr/local/lib/python2.4/site-packages/django/db/models/query.py", line 114, in __iter__
    return iter(self._get_data())
  File "/usr/local/lib/python2.4/site-packages/django/db/models/query.py", line 482, in _get_data
    self._result_cache = list(self.iterator())
  File "/usr/local/lib/python2.4/site-packages/django/db/models/query.py", line 180, in iterator
    select, sql, params = self._get_sql_clause()
  File "/usr/local/lib/python2.4/site-packages/django/db/models/query.py", line 497, in _get_sql_clause
    joins2, where2, params2 = self._filters.get_sql(opts)
  File "/usr/local/lib/python2.4/site-packages/django/db/models/query.py", line 719, in get_sql
    joins2, where2, params2 = val.get_sql(opts)
  File "/usr/local/lib/python2.4/site-packages/django/db/models/query.py", line 770, in get_sql
    return parse_lookup(self.kwargs.items(), opts)
  File "/usr/local/lib/python2.4/site-packages/django/db/models/query.py", line 925, in parse_lookup
    joins2, where2, params2 = lookup_inner(path, lookup_type, value, opts, opts.db_table, None)
  File "/usr/local/lib/python2.4/site-packages/django/db/models/query.py", line 990, in lookup_inner
    field = find_field(name, current_opts.get_all_related_many_to_many_objects(), True)
  File "/usr/local/lib/python2.4/site-packages/django/db/models/options.py", line 187, in get_all_related_many_to_many_objects
    for klass in get_models():
  File "/usr/local/lib/python2.4/site-packages/django/db/models/loading.py", line 134, in get_models
    self._populate()
  File "/usr/local/lib/python2.4/site-packages/django/db/models/loading.py", line 55, in _populate
    self.load_app(app_name, True)
  File "/usr/local/lib/python2.4/site-packages/django/db/models/loading.py", line 70, in load_app
    mod = __import__(app_name, {}, {}, ['models'])
ImportError: No module named mysite.myapp
[root@boo ~/projects/mysite]# cd /usr/local/src/django
[root@boo /usr/local/src/django]# svn up -r 6086
U    django/test/client.py
U    django/test/testcases.py
.....
U    docs/templates_python.txt
Updated to revision 6086.
[root@boo /usr/local/src/django]# cd ~/projects/mysite
[root@boo ~/projects/mysite]# ./manage.py --version 
0.97-pre-SVN-6086
[root@boo ~/projects/mysite]# ./daily_cleanup.py 
[root@boo ~/projects/mysite]#

This is a BUG, because up to [6087] it worked perfectly!
TestCase in attach.

comment:15 by anonymous, 17 years ago

Owner: changed from emperorcezar to Adrian Holovaty
Status: reopenednew

in reply to:  14 comment:16 by Malcolm Tredinnick, 17 years ago

Resolution: invalid
Status: newclosed

Replying to boobsd@gmail.com:

This is a BUG, because up to [6087] it worked perfectly!

This isn't a bug. Prior to [6087], the import error was masked and Django struggled on anyway. This wasn't really correct behaviour. Now we display this error, because it's something that should be fixed.

The problem is with your Python path here. When you run something via manage.py, it puts the parent directory of manage.py into the python path automatically. However, that is not something Python does normally and so when daily_cleanup.py is run from the command line inside your project directory, it will only have the current directory in the path, not the "mysite" directory. In production, you would be running daily_cleanup.py with Python paths already correctly configured and so this is just some extra care you have to taken when testing it manually like this as well.

comment:17 by Malcolm Tredinnick, 17 years ago

Oops.. typo in the above comment. It's not having the mysite directory in the path that's the problem. It's not having the parent of mysite in the path. You need to be able to run "from mysite import myapp" and not have it fail.

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