[Django] #20463: .get_or_create() leaves Postgres in 'current transaction is aborted...' state if da DataError occurs in create

18 views
Skip to first unread message

Django

unread,
May 19, 2013, 9:00:08 AM5/19/13
to django-...@googlegroups.com
#20463: .get_or_create() leaves Postgres in 'current transaction is aborted...'
state if da DataError occurs in create
----------------------------------------------+--------------------
Reporter: UloPe | Owner: nobody
Type: Bug | Status: new
Component: Database layer (models, ORM) | Version: 1.4
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------------------+--------------------
Calling .get_or_create() with invalid data (e.g. broken UTF-8) in any of
the fields in the 'default' argument causes a DataError (previously
DatabaseError) to be thrown.

On Postgres this leads to the current transaction being left in the
"InternalError: current transaction is aborted, commands ignored until end
of transaction block" state.

The reason for this is that .get_or_create() creates a savepoint but only
rolls it back on IntegrityError, which DataError is not a subclass of.

I'll attach a diff with a test for this behaviour.

--
Ticket URL: <https://code.djangoproject.com/ticket/20463>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
May 20, 2013, 11:48:55 AM5/20/13
to django-...@googlegroups.com
#20463: .get_or_create() leaves Postgres in 'current transaction is aborted...'
state if da DataError occurs in create
-------------------------------------+-------------------------------------

Reporter: UloPe | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.4
(models, ORM) | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by claudep):

* needs_better_patch: => 0
* stage: Unreviewed => Accepted
* needs_tests: => 0
* needs_docs: => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/20463#comment:1>

Django

unread,
May 21, 2013, 7:01:38 PM5/21/13
to django-...@googlegroups.com
#20463: .get_or_create() leaves Postgres in 'current transaction is aborted...'
state if da DataError occurs in create
-------------------------------------+-------------------------------------

Reporter: UloPe | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.4
(models, ORM) | Resolution:
Severity: Release blocker | Triage Stage: Accepted

Keywords: | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by russellm):

* severity: Normal => Release blocker


Comment:

Marking as a release blocker because it relates to some refactoring
introduced in [59a35208]

--
Ticket URL: <https://code.djangoproject.com/ticket/20463#comment:2>

Django

unread,
May 22, 2013, 5:11:48 AM5/22/13
to django-...@googlegroups.com
#20463: .get_or_create() leaves Postgres in 'current transaction is aborted...'
state if da DataError occurs in create
-------------------------------------+-------------------------------------

Reporter: UloPe | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.4
(models, ORM) | Resolution:
Severity: Release blocker | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by aaugustin):

UloPe: there's no reason why this test should be specific to PostgreSQL,
this behavior should be guaranteed on all databases.

Russell: I'm not convinced it's a regression, but it's obviously a bug and
it's fast to fix it, so I haven't investigated further!

--
Ticket URL: <https://code.djangoproject.com/ticket/20463#comment:3>

Django

unread,
May 22, 2013, 5:12:12 AM5/22/13
to django-...@googlegroups.com
#20463: .get_or_create() leaves Postgres in 'current transaction is aborted...'
state if da DataError occurs in create
-------------------------------------+-------------------------------------
Reporter: UloPe | Owner: nobody
Type: Bug | Status: closed

Component: Database layer | Version: 1.4
(models, ORM) | Resolution: fixed

Severity: Release blocker | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by Aymeric Augustin <aymeric.augustin@…>):

* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"0e51d8eb66121b2558a38c9f4e366df781046873"]:
{{{
#!CommitTicketReference repository=""
revision="0e51d8eb66121b2558a38c9f4e366df781046873"
Fixed #20463 -- Made get_or_create more robust.

When an exception other than IntegrityError was raised, get_or_create
could fail and leave the database connection in an unusable state.

Thanks UloPe for the report.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/20463#comment:4>

Reply all
Reply to author
Forward
0 new messages