#36785: v6 seems to break the behaviour of transaction.atomic
-------------------------------------+-------------------------------------
     Reporter:  Paul Zakin           |                    Owner:  (none)
         Type:  Bug                  |                   Status:  closed
    Component:  Database layer       |                  Version:  6.0
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:  invalid
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

 * resolution:   => invalid
 * status:  new => closed

Comment:

 Well I think you have your answer here.

 Prior to #36490 (e1671278e88265e64811657b8b939b5d786295cb) `bulk_create`
 was always creating an implicit transaction even if it only needed to
 issue a single `INSERT`.

 Now that no explicit `transaction.atomic` usage is made the database error
 your RLS policy triggers and don't let the error reach
 `transaction.Atomic.__exit__` which goes against its documented usage (see
 
[https://docs.djangoproject.com/en/6.0/topics/db/transactions/#django.db.transaction.atomic
 Avoid catching exceptions inside atomic!]) it leaves the current
 transaction in an incoherent state.

 TL;DR your usage of `transaction.atomic` is incorrect but it was masked by
 `bulk_create` creating a nested `atomic` previously (which was
 implementation detail) and you should do the following instead

 {{{#!python
 try:
     with transaction.atomic():
         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"'
 }}}
-- 
Ticket URL: <https://code.djangoproject.com/ticket/36785#comment:5>
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/0107019b01776d20-e242815a-b9c4-4a43-bb0f-b408293ffbc6-000000%40eu-central-1.amazonses.com.

Reply via email to