Opened 6 months ago

Last modified 6 months ago

#28263 new Bug

TestCase breaks for databases that don't support savepoints

Reported by: Lokesh Dokara Owned by: nobody
Component: Testing framework Version: 1.11
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

TestCases with more than one test fail with

TransactionManagementError: An error occurred in the current transaction. You can't execute queries until the end of the 'atomic' block.

when uses_savepoints = False and supports_transactions = True.

To reproduce this issue set uses_savepoints = False for any of the backends other than MySQL with MyISAM as MyISAM engine doesn't transactions as well. This setting can be set in any of the following files according to the database used.

  • django/db/backends/postgresql/features.py
  • django/db/backends/mysql/features.py
  • django/db/backends/sqlite3/features.py

I feel this case is not handled in the implementation of TestCase.

Change History (6)

comment:1 Changed 6 months ago by Tim Graham

Could you motive this? Are you writing a database backend for a database that supports transactions but not savepoints?

comment:2 in reply to:  1 Changed 6 months ago by Lokesh Dokara

Replying to Tim Graham:

Yeah, exactly I am writing a backend for CockroachDB which supports transactions but does not have full support for savepoints. So I am currently unable to properly test this backend because of this issue.

Could you motive this? Are you writing a database backend for a database that supports transactions but not savepoints?

comment:3 Changed 6 months ago by Tim Graham

I'm not sure what the expected behavior is. Can you propose a patch? Maybe connections_support_transactions() should also consider uses_savepoints?

comment:4 Changed 6 months ago by Tim Graham

Triage Stage: UnreviewedAccepted

comment:5 Changed 6 months ago by Simon Charette

Since da9fe5c717c179a9e881a40efd3bfe36a21bf4a6 (#20392) TestCase subclasses execution is wrapped in a transaction per-db on class setup and each method is wrapped in a save point per-db.

In your case I think you'd want to disable the transaction wrapping at the class level so test method get wrapped in a transaction instead of save points. I think you should be able to achieve that by also checking that all connections support save points in TestCase.setUpClass() and tearDownClass().

Last edited 6 months ago by Simon Charette (previous) (diff)

comment:6 in reply to:  5 Changed 6 months ago by Lokesh Dokara

Replying to Simon Charette:
I think we might also need to modify _should_reload_connections(), _fixture_setup(), _fixture_teardown() to achieve that.

In your case I think you'd want to disable the transaction wrapping at the class level so test method get wrapped in a transaction instead of save points. I think you should be able to achieve that by also checking that all connections support save points in TestCase.setUpClass() and tearDownClass().

Note: See TracTickets for help on using tickets.
Back to Top