Opened 12 years ago

Closed 12 years ago

#20463 closed Bug (fixed)

.get_or_create() leaves Postgres in 'current transaction is aborted...' state if da DataError occurs in create

Reported by: Ulrich Petri Owned by: nobody
Component: Database layer (models, ORM) Version: 1.4
Severity: Release blocker Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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.

Attachments (1)

get_or_create_pgsql-test.diff (1.3 KB ) - added by Ulrich Petri 12 years ago.

Download all attachments as: .zip

Change History (5)

by Ulrich Petri, 12 years ago

comment:1 by Claude Paroz, 12 years ago

Triage Stage: UnreviewedAccepted

comment:2 by Russell Keith-Magee, 12 years ago

Severity: NormalRelease blocker

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

comment:3 by Aymeric Augustin, 12 years ago

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!

comment:4 by Aymeric Augustin <aymeric.augustin@…>, 12 years ago

Resolution: fixed
Status: newclosed

In 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.

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