Code

#20463 closed Bug (fixed)

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

Reported by: UloPe 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 UloPe 14 months ago.

Download all attachments as: .zip

Change History (5)

Changed 14 months ago by UloPe

comment:1 Changed 14 months ago by claudep

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 14 months ago by russellm

  • Severity changed from Normal to Release blocker

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

comment:3 Changed 14 months ago 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!

comment:4 Changed 14 months ago by Aymeric Augustin <aymeric.augustin@…>

  • Resolution set to fixed
  • Status changed from new to closed

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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.