#12387: TransactionRollbackError when there are more ForeignKey's to one table
------------------------------------+---------------------------------------
Reporter: [email protected] | Owner: nobody
Status: closed | Milestone:
Component: Uncategorized | Version: 1.1
Resolution: invalid | Keywords:
Stage: Unreviewed | Has_patch: 0
Needs_docs: 0 | Needs_tests: 0
Needs_better_patch: 0 |
------------------------------------+---------------------------------------
Changes (by russellm):
* status: new => closed
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
* resolution: => invalid
Old description:
> Postgres backend. When there is more references to one table with
> ForeignKey in same model sometimes there is thrown Exception (not
> always).
>
> File "/usr/local/lib/python2.6/site-packages/django/db/models/base.py",
> line 410, in save
> self.save_base(force_insert=force_insert, force_update=force_update)
>
> File "/usr/local/lib/python2.6/site-packages/django/db/models/base.py",
> line 495, in save_base
> result = manager._insert(values, return_id=update_pk)
>
> File "/usr/local/lib/python2.6/site-
> packages/django/db/models/manager.py", line 177, in _insert
> return insert_query(self.model, values, **kwargs)
>
> File "/usr/local/lib/python2.6/site-packages/django/db/models/query.py",
> line 1087, in insert_query
> return query.execute_sql(return_id)
>
> File "/usr/local/lib/python2.6/site-
> packages/django/db/models/sql/subqueries.py", line 320, in execute_sql
> cursor = super(InsertQuery, self).execute_sql(None)
>
> File "/usr/local/lib/python2.6/site-
> packages/django/db/models/sql/query.py", line 2369, in execute_sql
> cursor.execute(sql, params)
>
> TransactionRollbackError: deadlock detected
> DETAIL: Process 40975 waits for ShareLock on transaction 172977254;
> blocked by process 40961.
> Process 40961 waits for ShareLock on transaction 172977277; blocked by
> process 40975.
> HINT: See server log for query details.
> CONTEXT: SQL statement "SELECT 1 FROM ONLY "public"."foo_bar" x WHERE
> "id" OPERATOR(pg_catalog.=) $1 FOR SHARE OF x"
>
> Example of model:
>
> class bar(models.Model):
> baz = models.ForeignKey('some.model', related_name='sm')
> other = models.ForeignKey('some.model', related_name='so')
New description:
Postgres backend. When there is more references to one table with
ForeignKey in same model sometimes there is thrown Exception (not always).
{{{
File "/usr/local/lib/python2.6/site-packages/django/db/models/base.py",
line 410, in save
self.save_base(force_insert=force_insert, force_update=force_update)
File "/usr/local/lib/python2.6/site-packages/django/db/models/base.py",
line 495, in save_base
result = manager._insert(values, return_id=update_pk)
File "/usr/local/lib/python2.6/site-
packages/django/db/models/manager.py", line 177, in _insert
return insert_query(self.model, values, **kwargs)
File "/usr/local/lib/python2.6/site-packages/django/db/models/query.py",
line 1087, in insert_query
return query.execute_sql(return_id)
File "/usr/local/lib/python2.6/site-
packages/django/db/models/sql/subqueries.py", line 320, in execute_sql
cursor = super(InsertQuery, self).execute_sql(None)
File "/usr/local/lib/python2.6/site-
packages/django/db/models/sql/query.py", line 2369, in execute_sql
cursor.execute(sql, params)
TransactionRollbackError: deadlock detected
DETAIL: Process 40975 waits for ShareLock on transaction 172977254;
blocked by process 40961.
Process 40961 waits for ShareLock on transaction 172977277; blocked by
process 40975.
HINT: See server log for query details.
CONTEXT: SQL statement "SELECT 1 FROM ONLY "public"."foo_bar" x WHERE
"id" OPERATOR(pg_catalog.=) $1 FOR SHARE OF x"
}}}
Example of model:
{{{
class bar(models.Model):
baz = models.ForeignKey('some.model', related_name='sm')
other = models.ForeignKey('some.model', related_name='so')
}}}
Comment:
There isn't enough detail here to reproduce the problem. The error
suggests that the problem lies with some subtle interaction with
transactions, but without more detail on what you were doing at the time
you issued the save (including the state of any open transactions) it's
impossible to say for sure.
--
Ticket URL: <http://code.djangoproject.com/ticket/12387#comment:1>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" 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-updates?hl=en.