#36785: v6 seems to break the behaviour of transaction.atomic
-------------------------------------+-------------------------------------
Reporter: paulzakin | Type: Bug
Status: new | Component: Database
| layer (models, ORM)
Version: 6.0 | Severity: Normal
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Hello!
Just tried upgrading to v6 - and this snippet from a test (django and
pytest) now breaks. Now, the first chunk passses but the second chunk
requires a "current transaction is aborted, commands ignored until end of
transaction block".
Historically, I got around that by wrapping the test in an with
transaction.atomic() to prevent the error from moving to the next part of
the test - but that no longer works.
Not sure if this counts as an error - but I'm not supposed to do this in a
test anyway! But it did break from v5 to v6.
{{{
# Do policies apply to .bulk_create()?
with transaction.atomic(): # Required as any database error, like
RLS, must be in transaction.atomic()
try:
Foo.objects.bulk_create([Foo(name="Foo", study_id=study.pk)])
force_test_to_fail()
except Exception as error:
assert str(error) == 'new row violates row-level security
policy for table "foo"'
with transaction.atomic(): # Required as any database error, like
RLS, must be in transaction.atomic()
try:
# Do policies apply to .bulk_update()?
foo.name = "XXX"
# No rows should have been updated, because the admin does not
have access to the id
Foo.objects.bulk_update([foo], fields=["*"])
force_test_to_fail()
except Exception as error:
assert str(error) == f"id: {foo.pk} in table: foo does not
exist!"
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36785>
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 visit
https://groups.google.com/d/msgid/django-updates/0107019aff544c3c-93db1c93-fe87-41db-bff7-5880719a5d70-000000%40eu-central-1.amazonses.com.