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?
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
SQL-Queries:
0.004 SELECT "django_session"."session_key",
"django_session"."session_data", "django_session"."expire_date" FROM
"django_session" WHERE ("django_session"."session_key" =
'364c6ecup90613a766e06a8bb118160be0' AND "django_session"."expire_date"
> '2008-12-10 13:27:34.226733' )
0.001 SELECT "auth_user"."id", "auth_user"."username",
"auth_user"."first_name", "auth_user"."last_name", "auth_user"."email",
"auth_user"."password", "auth_user"."is_staff", "auth_user"."is_active",
"auth_user"."is_superuser", "auth_user"."last_login",
"auth_user"."date_joined" FROM "auth_user" WHERE "auth_user"."id" = 1
0.000 SET LOCAL foo.user_id TO 1
0.001 SELECT "foo_userprofile"."id", "foo_userprofile"."user_id",
"foo_userprofile"."send_inbox_mail",
"foo_userprofile"."form_koerbe_hide_if_no_perm",
"foo_userprofile"."form_koerbe_hide_if_no_belege" FROM "foo_userprofile"
WHERE "foo_userprofile"."user_id" = 1
0.002 SELECT "foo_belegart"."id", "foo_belegart"."parent_id",
"foo_belegart"."name", "foo_belegart"."duration", "foo_belegart"."text",
"foo_belegart"."default_gruppe_id", "foo_belegart"."archiv_belegart"
FROM "foo_belegart"
0.001 SELECT "foo_buchungskreis"."id", "foo_buchungskreis"."name",
"foo_buchungskreis"."email_footer", "foo_buchungskreis"."email_adresse",
"foo_buchungskreis"."default" FROM "foo_buchungskreis"
0.003 SELECT "auth_permission"."id", "auth_permission"."name",
"auth_permission"."content_type_id", "auth_permission"."codename" FROM
"auth_permission" INNER JOIN "django_content_type" ON
("auth_permission"."content_type_id" = "django_content_type"."id") WHERE
("auth_permission"."codename" = 'change_belegart' AND
"django_content_type"."app_label" = 'foo' ) ORDER BY
"django_content_type"."app_label" ASC, "auth_permission"."codename" ASC
0.000 SELECT "foo_belegart"."id", "foo_belegart"."parent_id",
"foo_belegart"."name", "foo_belegart"."duration", "foo_belegart"."text",
"foo_belegart"."default_gruppe_id", "foo_belegart"."archiv_belegart"
FROM "foo_belegart" WHERE "foo_belegart"."id" = 1142
0.000 SELECT "foo_belegart"."id", "foo_belegart"."parent_id",
"foo_belegart"."name", "foo_belegart"."duration", "foo_belegart"."text",
"foo_belegart"."default_gruppe_id", "foo_belegart"."archiv_belegart"
FROM "foo_belegart" WHERE "foo_belegart"."parent_id" = 1142 ORDER BY
"foo_belegart"."name" ASC
0.000 SELECT "foo_belegart"."id", "foo_belegart"."parent_id",
"foo_belegart"."name", "foo_belegart"."duration", "foo_belegart"."text",
"foo_belegart"."default_gruppe_id", "foo_belegart"."archiv_belegart"
FROM "foo_belegart" WHERE "foo_belegart"."id" = 1082
0.000 SELECT "foo_belegart"."id", "foo_belegart"."parent_id",
"foo_belegart"."name", "foo_belegart"."duration", "foo_belegart"."text",
"foo_belegart"."default_gruppe_id", "foo_belegart"."archiv_belegart"
FROM "foo_belegart" WHERE "foo_belegart"."id" = 1034
0.001 SELECT "foo_index"."id" FROM "foo_index" INNER JOIN
"foo_belegart_indexes" ON ("foo_index"."id" =
"foo_belegart_indexes"."index_id") WHERE
"foo_belegart_indexes"."belegart_id" = 1142
0.000 SELECT "foo_index"."id" FROM "foo_index" INNER JOIN
"foo_belegart_indexes" ON ("foo_index"."id" =
"foo_belegart_indexes"."index_id") WHERE
"foo_belegart_indexes"."belegart_id" = 1082
0.000 SELECT "foo_index"."id" FROM "foo_index" INNER JOIN
"foo_belegart_indexes" ON ("foo_index"."id" =
"foo_belegart_indexes"."index_id") WHERE
"foo_belegart_indexes"."belegart_id" = 1034
0.000 SELECT "foo_belegart"."id", "foo_belegart"."parent_id",
"foo_belegart"."name", "foo_belegart"."duration", "foo_belegart"."text",
"foo_belegart"."default_gruppe_id", "foo_belegart"."archiv_belegart"
FROM "foo_belegart" WHERE "foo_belegart"."id" = 1082
0.000 SELECT "foo_belegart"."id", "foo_belegart"."parent_id",
"foo_belegart"."name", "foo_belegart"."duration", "foo_belegart"."text",
"foo_belegart"."default_gruppe_id", "foo_belegart"."archiv_belegart"
FROM "foo_belegart" WHERE "foo_belegart"."id" = 1034
0.001 SELECT "auth_group"."id", "auth_group"."name" FROM "auth_group"
0.000 SELECT "foo_index"."id" FROM "foo_index"
0.001 SELECT "auth_permission"."id", "auth_permission"."name",
"auth_permission"."content_type_id", "auth_permission"."codename" FROM
"auth_permission" INNER JOIN "django_content_type" ON
("auth_permission"."content_type_id" = "django_content_type"."id") WHERE
("auth_permission"."codename" = 'view_belegart' AND
"django_content_type"."app_label" = 'foo' ) ORDER BY
"django_content_type"."app_label" ASC, "auth_permission"."codename" ASC
0.001 SELECT "foo_belegartrequiredgroup"."id",
"foo_belegartrequiredgroup"."belegart_id",
"foo_belegartrequiredgroup"."permission_id",
"foo_belegartrequiredgroup"."group_id" FROM "foo_belegartrequiredgroup"
WHERE ("foo_belegartrequiredgroup"."belegart_id" = 1142 AND
"foo_belegartrequiredgroup"."permission_id" = 64 )
0.000 SELECT "auth_group"."id", "auth_group"."name" FROM "auth_group"
WHERE "auth_group"."id" = 10
0.001 SELECT "auth_permission"."id", "auth_permission"."name",
"auth_permission"."content_type_id", "auth_permission"."codename" FROM
"auth_permission" INNER JOIN "django_content_type" ON
("auth_permission"."content_type_id" = "django_content_type"."id") WHERE
("auth_permission"."codename" = 'change_belegart' AND
"django_content_type"."app_label" = 'foo' ) ORDER BY
"django_content_type"."app_label" ASC, "auth_permission"."codename" ASC
0.000 SELECT "foo_belegartrequiredgroup"."id",
"foo_belegartrequiredgroup"."belegart_id",
"foo_belegartrequiredgroup"."permission_id",
"foo_belegartrequiredgroup"."group_id" FROM "foo_belegartrequiredgroup"
WHERE ("foo_belegartrequiredgroup"."belegart_id" = 1142 AND
"foo_belegartrequiredgroup"."permission_id" = 26 )
0.000 SELECT "auth_group"."id", "auth_group"."name" FROM "auth_group"
WHERE "auth_group"."id" = 10
0.001 SELECT "auth_permission"."id", "auth_permission"."name",
"auth_permission"."content_type_id", "auth_permission"."codename" FROM
"auth_permission" INNER JOIN "django_content_type" ON
("auth_permission"."content_type_id" = "django_content_type"."id") WHERE
("auth_permission"."codename" = 'view_belegart' AND
"django_content_type"."app_label" = 'foo' ) ORDER BY
"django_content_type"."app_label" ASC, "auth_permission"."codename" ASC
0.000 SELECT "foo_belegartrequiredgroup"."id",
"foo_belegartrequiredgroup"."belegart_id",
"foo_belegartrequiredgroup"."permission_id",
"foo_belegartrequiredgroup"."group_id" FROM "foo_belegartrequiredgroup"
WHERE ("foo_belegartrequiredgroup"."belegart_id" = 1142 AND
"foo_belegartrequiredgroup"."permission_id" = 64 )
0.001 SELECT "auth_permission"."id", "auth_permission"."name",
"auth_permission"."content_type_id", "auth_permission"."codename" FROM
"auth_permission" INNER JOIN "django_content_type" ON
("auth_permission"."content_type_id" = "django_content_type"."id") WHERE
("auth_permission"."codename" = 'change_belegart' AND
"django_content_type"."app_label" = 'foo' ) ORDER BY
"django_content_type"."app_label" ASC, "auth_permission"."codename" ASC
0.000 SELECT "foo_belegartrequiredgroup"."id",
"foo_belegartrequiredgroup"."belegart_id",
"foo_belegartrequiredgroup"."permission_id",
"foo_belegartrequiredgroup"."group_id" FROM "foo_belegartrequiredgroup"
WHERE ("foo_belegartrequiredgroup"."belegart_id" = 1142 AND
"foo_belegartrequiredgroup"."permission_id" = 26 )
0.000 SELECT "auth_group"."id", "auth_group"."name" FROM "auth_group"
WHERE "auth_group"."id" = 10
0.000 SELECT "auth_group"."id", "auth_group"."name" FROM "auth_group"
WHERE "auth_group"."id" = 10
0.000 SELECT "foo_index"."id" FROM "foo_index" WHERE "foo_index"."id" =
'ISU'
0.001 SELECT "foo_index"."id" FROM "foo_index" INNER JOIN
"foo_belegart_indexes" ON ("foo_index"."id" =
"foo_belegart_indexes"."index_id") WHERE
"foo_belegart_indexes"."belegart_id" IN (1142, 1082, 1034)
0.000 SELECT "foo_index"."id" FROM "foo_index" WHERE "foo_index"."id" =
'ISU'
0.001 SELECT "foo_index"."id" FROM "foo_index" INNER JOIN
"foo_belegart_indexes" ON ("foo_index"."id" =
"foo_belegart_indexes"."index_id") WHERE
"foo_belegart_indexes"."belegart_id" IN (1142, 1082, 1034)
0.001 SELECT "foo_isu_belegart_contact_klasse"."id",
"foo_isu_belegart_contact_klasse"."belegart_id",
"foo_isu_belegart_contact_klasse"."cls",
"foo_isu_belegart_contact_klasse"."activity" FROM
"foo_isu_belegart_contact_klasse" WHERE
"foo_isu_belegart_contact_klasse"."belegart_id" = 1142
0.000 SELECT "foo_isu_belegart_contact_klasse"."id",
"foo_isu_belegart_contact_klasse"."belegart_id",
"foo_isu_belegart_contact_klasse"."cls",
"foo_isu_belegart_contact_klasse"."activity" FROM
"foo_isu_belegart_contact_klasse" WHERE
"foo_isu_belegart_contact_klasse"."belegart_id" = 1142
0.000 SELECT "foo_isu_belegart_contact_klasse"."id",
"foo_isu_belegart_contact_klasse"."belegart_id",
"foo_isu_belegart_contact_klasse"."cls",
"foo_isu_belegart_contact_klasse"."activity" FROM
"foo_isu_belegart_contact_klasse" WHERE
"foo_isu_belegart_contact_klasse"."belegart_id" = 1082
0.000 SELECT "foo_isu_belegart_contact_klasse"."id",
"foo_isu_belegart_contact_klasse"."belegart_id",
"foo_isu_belegart_contact_klasse"."cls",
"foo_isu_belegart_contact_klasse"."activity" FROM
"foo_isu_belegart_contact_klasse" WHERE
"foo_isu_belegart_contact_klasse"."belegart_id" = 1034
0.000 SELECT "foo_belegart"."id", "foo_belegart"."parent_id",
"foo_belegart"."name", "foo_belegart"."duration", "foo_belegart"."text",
"foo_belegart"."default_gruppe_id", "foo_belegart"."archiv_belegart"
FROM "foo_belegart" WHERE "foo_belegart"."id" = 1142
0.000 SELECT "foo_belegart"."id", "foo_belegart"."parent_id",
"foo_belegart"."name", "foo_belegart"."duration", "foo_belegart"."text",
"foo_belegart"."default_gruppe_id", "foo_belegart"."archiv_belegart"
FROM "foo_belegart" WHERE "foo_belegart"."id" = 1082
0.000 SELECT "foo_belegart"."id", "foo_belegart"."parent_id",
"foo_belegart"."name", "foo_belegart"."duration", "foo_belegart"."text",
"foo_belegart"."default_gruppe_id", "foo_belegart"."archiv_belegart"
FROM "foo_belegart" WHERE "foo_belegart"."id" = 1034
--
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de
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