Opened 15 years ago

Closed 15 years ago

#12387 closed (invalid)

TransactionRollbackError when there are more ForeignKey's to one table

Reported by: szymon@… Owned by: nobody
Component: Uncategorized Version: 1.1
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Russell Keith-Magee)

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')

Change History (1)

comment:1 by Russell Keith-Magee, 15 years ago

Description: modified (diff)
Resolution: invalid
Status: newclosed

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.

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