Hello,
I'm trying to debug some model functions by setting up a script to use
an environment similar to "manage.py shell". I can get a single item
from the model from the command line, but when I use the script I get a
StopIteration exception.
More generally, I'm very new to django and pretty new to python and
would like advice on how to configure environment and what to put in
scripts in order to be able to write scripts to do things like
unit-testing my django code and populating databases from external
sources, and run those scripts in a debugger e.g. Wing.
I've searched the wiki and django-users archives and django
documentation and didn't find much beyond what's shown below - but that
may be poor search skills. Pointers appreciated.
Many thanks in advance.
Details on the exception --
Getting one item works from the command line:
----------------------------------------------
$ python manage.py shell
Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit
(Intel) on win32]
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
import inputs.models
oi015 = inputs.models.OI.objects.get(id=15)
oi015
<OI: oi015>
But getting one item from the script fails (ran this from Wing):
----------------------------------------------------------------
from django.core.management import setup_environ
import settings
setup_environ(settings)
import inputs.models
oi015=inputs.models.OI.objects.get(id=15)
StopIteration:
Traceback (innermost last):
File "C:\Documents and
Settings\Administrator\Desktop\trunk\input\ngats_input\models_tests.py",
line 1, in <module>
'test script for indirect_grid'
File "C:\Documents and
Settings\Administrator\Desktop\trunk\input\ngats_input\models_tests.py",
line 9, in <module>
oi015=inputs.models.OI.objects.get(id=15)
File "C:\cygwin\home\Dan\src\django_src\django\db\models\manager.py",
line 67, in get
return self.get_query_set().get(*args, **kwargs)
File "C:\cygwin\home\Dan\src\django_src\django\db\models\query.py",
line 211, in get
obj_list = list(clone)
File "C:\cygwin\home\Dan\src\django_src\django\db\models\query.py",
line 103, in __iter__
return iter(self._get_data())
File "C:\cygwin\home\Dan\src\django_src\django\db\models\query.py",
line 430, in _get_data
self._result_cache = list(self.iterator())
File "C:\cygwin\home\Dan\src\django_src\django\db\models\query.py",
line 178, in iterator
raise StopIteration
The exception occurs in django/db/models/query.py:
-----------------------------------------------------
def iterator(self):
"Performs the SELECT database lookup of this QuerySet."
# self._select is a dictionary, and dictionaries' key order is
# undefined, so we convert it to a list of tuples.
extra_select = self._select.items()
cursor = connection.cursor()
select, sql, params = self._get_sql_clause()
cursor.execute("SELECT " + (self._distinct and "DISTINCT " or
"") + ",".join(select) + sql, params)
fill_cache = self._select_related
index_end = len(self.model._meta.fields)
while 1:
rows = cursor.fetchmany(GET_ITERATOR_CHUNK_SIZE)
if not rows:
raise StopIteration ### <<< HERE
for row in rows:
if fill_cache:
obj, index_end = get_cached_row(self.model, row, 0)
else:
obj = self.model(*row[:index_end])
for i, k in enumerate(extra_select):
setattr(obj, k[0], row[index_end+i])
yield obj
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django
users" 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-users?hl=en
-~----------~----~----~----~------~----~------~--~---