On Wed, 2008-12-10 at 13:32 +0100, Thomas Guettler wrote:
> Hi,
> 
> I get this error from psycopg2: "InterfaceError: cursor already closed"
> 
> The error is repeatable, but not the way you would expect.
> 
> The error happens at id 1142. If I use objects.filter.(id__gt=1140)
> instead of all() it does not happen.
> 
> Has someone seen something like this before?

I've seen it plenty of times. Every single time was a bug in my code and
I haven't seen it since about March of this year on PostgreSQL. :-)

Of course, "my code" often included when I was working on Django's ORM,
so this could also be a bug in "my code". But I thought we were avoiding
doing anything silly these days.

> PostgreSQL 8.2.6 on x86_64-unknown-linux-gnu, compiled by GCC gcc (GCC)
> 4.2.1 (SUSE Linux)
> python-psycopg2-2.0.5.1-2
> django 1.0.2
> 
> Traceback (most recent call last):
>   File "/home/mwtest/foo/tests/ReadonlyTestPostInit.py", line 104, in
> testBelegartEditView
>     for belegart in Belegart.objects.all().order_by('id'):
>   File "/home/mwtest/django/db/models/query.py", line 185, in _result_iter
>     self._fill_cache()
>   File "/home/mwtest/django/db/models/query.py", line 618, in _fill_cache
>     self._result_cache.append(self._iter.next())
>   File "/home/mwtest/django/db/models/query.py", line 275, in iterator
>     for row in self.query.results_iter():
>   File "/home/mwtest/django/db/models/sql/query.py", line 206, in
> results_iter
>     for rows in self.execute_sql(MULTI):
>   File "/home/mwtest/django/db/models/sql/query.py", line 1748, in <lambda>
>     result = iter((lambda: cursor.fetchmany(GET_ITERATOR_CHUNK_SIZE)),
> InterfaceError: cursor already closed

This isn't quite enough to work out what the problem might be.

Can you reproduce the problem when that statement is the only thing in
test and that test is the only thing you run (e.g. if you do
list(objects.filter.(id__gt=1140) to force the query to be run)? If not,
of course, how small can you make things to repeat the problem.

The general situation where I've run into that problem was either when
mixing reads and writes to the database (partially processing a queryset
whilst also making updates and inserts) or when using simultaneous
iterators on the same queryset. However, both those situations shouldn't
be problematic any longer (and psycopg(2) is able to handle cursors
reading whilst other cursors write).

So what's the smallest amount of code that demonstrates the problem. If
you can show me that, I can probably suggest how to debug it further, or
at least think about what might be causing it.

Regards,
Malcolm


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to