﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
36785	bulk_create lack of implicit transaction.atomic usage surfaces improper nested error handling	Paul Zakin		"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!""
}}}

"	Bug	closed	Database layer (models, ORM)	6.0	Normal	invalid			Unreviewed	0	0	0	0	0	0
