#32248: get_object_or_404() leaves postgres in 'current transaction is
aborted...'
state if invalid data is passed as input to the get_object_or_404.
-------------------------------------+-------------------------------------
Reporter: | Owner: nobody
artstyle46 |
Type: Bug | Status: new
Component: Utilities | Version: 2.2
Severity: Normal | Keywords: postgres
| transaction_aborted
Triage Stage: | get_object_or_404
Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
-------------------------------------+-------------------------------------
calling get_object_or_404() with invalid data (e.g. invalid UUID) in any
of the fields causes Postgres to stay in the same transaction. On
Postgres, this leads to the failure of any new query using the same
connection. The reason for this is Postgres on getting invalid input
doesn't rollback the transaction automatically and neither does Django
explicitly rollbacks such get calls, which leaves the database in an
unstable state.
Example code:
{{{
def invalid_data(model):
try:
obj=get_object_or_404(model, id=f"{invalid_data}")
except:
# do something
model.objects.first().field # this will fail with current
transaction is aborted error.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32248>
Django <https://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 unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/053.c4abc307498cfac91f4203ecbbd243b8%40djangoproject.com.