[Django] #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.

11 views
Skip to first unread message

Django

unread,
Dec 7, 2020, 4:13:21 PM12/7/20
to django-...@googlegroups.com
#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.

Django

unread,
Dec 7, 2020, 4:13:47 PM12/7/20
to django-...@googlegroups.com
#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: artstyle46 | Owner: nobody

Type: Bug | Status: new
Component: Utilities | Version: 2.2
Severity: Normal | Resolution:
Keywords: postgres | Triage Stage:
transaction_aborted | Unreviewed
get_object_or_404 |

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

* cc: artstyle46 (added)


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

Django

unread,
Dec 7, 2020, 11:40:31 PM12/7/20
to django-...@googlegroups.com
#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: Asit Kumar Singh | Owner: Nayan
| sharma
Type: Bug | Status: assigned
Component: Utilities | Version: 2.2

Severity: Normal | Resolution:
Keywords: postgres | Triage Stage:
transaction_aborted | Unreviewed
get_object_or_404 |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Nayan sharma):

* owner: nobody => Nayan sharma
* status: new => assigned


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

Django

unread,
Dec 7, 2020, 11:41:25 PM12/7/20
to django-...@googlegroups.com
#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: Asit Kumar Singh | Owner: Nayan
| sharma
Type: Bug | Status: assigned
Component: Utilities | Version: 2.2

Severity: Normal | Resolution:
Keywords: postgres | Triage Stage:
transaction_aborted | Unreviewed
get_object_or_404 |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Nayan sharma):

can anyone help me through this as this is going to be my first
contribution to Django.

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

Django

unread,
Dec 8, 2020, 12:56:24 AM12/8/20
to django-...@googlegroups.com
#32248: QuerySet.get() leaves postgres in 'current transaction is aborted...' state
if invalid data is passed.

-------------------------------------+-------------------------------------
Reporter: Asit Kumar Singh | Owner: Nayan
| sharma
Type: Bug | Status: closed
Component: Database layer | Version: 2.2
(models, ORM) |
Severity: Normal | Resolution: invalid

Keywords: postgres | Triage Stage:
transaction_aborted | Unreviewed
get_object_or_404 |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* status: assigned => closed
* resolution: => invalid
* component: Utilities => Database layer (models, ORM)
* easy: 1 => 0


Comment:

`get_object_or_404()` calls `QuerySet.get()` without anything fancy, so
it's not related with its implementation. It looks that you call
`invalid_data()` inside an atomic transaction, in such cases you shouldn't
catch exceptions, see
[https://docs.djangoproject.com/en/3.1/topics/db/transactions/#django.db.transaction.atomic
""Avoid catching exceptions inside atomic!""]. If it's not the case,
please provide a sample Django 3.1+ project that reproduces this issue
(Django 2.2 doesn't receive bugfixes anymore).

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

Reply all
Reply to author
Forward
0 new messages