Opened 4 months ago

Last modified 3 months ago

#31413 new Bug

migrations.test_loader not isolated on databases that don't support transactions.

Reported by: Tim Graham Owned by: nobody
Component: Migrations Version: 3.0
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

On databases that don't support transactions, the changes that each test in migrations.test_loader.LoaderTests makes to the django_migrations table isn't rolled back after each test, resulting in this failure:

======================================================================
FAIL: test_loading_squashed (migrations.test_loader.LoaderTests)
Tests loading a squashed migration
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/tim/code/django/django/test/utils.py", line 373, in inner
    return func(*args, **kwargs)
  File "/home/tim/code/django/tests/migrations/test_loader.py", line 255, in test_loading_squashed
    2,
AssertionError: 1 != 2

For example, to make test_check_consistent_history clean up after itself (this doesn't solve the issue as there are more tests that would need similar changes):

  • tests/migrations/test_loader.py

    diff --git a/tests/migrations/test_loader.py b/tests/migrations/test_loader.py
    index e3a635dc63..2b8f155c72 100644
    a b class LoaderTests(TestCase): 
    415415        )
    416416        with self.assertRaisesMessage(InconsistentMigrationHistory, msg):
    417417            loader.check_consistent_history(connection)
     418        recorder.record_unapplied('migrations', '0002_second')
    418419
    419420    @override_settings(
    420421        MIGRATION_MODULES={'migrations': 'migrations.test_migrations_squashed_extra'},

There might be a better solution.

Change History (5)

comment:1 Changed 4 months ago by felixxm

Summary: LoaderTests not isolated on databases that don't support transactionsmigrations.test_loader not isolated on databases that don't support transactions.
Triage Stage: UnreviewedAccepted

I confirmed that two tests in migrations.test_loader fail on databases that don't support transactions:

======================================================================
FAIL: test_loading_squashed (migrations.test_loader.LoaderTests)
Tests loading a squashed migration
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/felixx/repo/django/django/test/utils.py", line 381, in inner
    return func(*args, **kwargs)
  File "django/tests/migrations/test_loader.py", line 255, in test_loading_squashed
    2,
AssertionError: 1 != 2

======================================================================
FAIL: test_apply (migrations.test_loader.RecorderTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "django/tests/migrations/test_loader.py", line 39, in test_apply
    set(),
AssertionError: Items in the first set but not the second:
('myapp', '0432_ponies')

comment:2 Changed 4 months ago by Sanskar Jaiswal

I ran all migrations tests on a non-transactional database (MyISAM), and a total of 13 tests failed in migrations.test_loader, migrations.test_operations.py, migrations.test_executer.py and migrations.test_commands. Is this behaviour expected?

comment:3 Changed 4 months ago by Tim Graham

There might be other failures to fix beyond the scope of this ticket. MyISAM isn't tested on CI.

comment:4 Changed 4 months ago by Sanskar Jaiswal

The only fix I can think of is manually adding recorder.record_unapplied to all tests which execute recorder.record_applied. Does anyone have a better solution?

comment:5 Changed 3 months ago by Tim Graham

How about adding a helper method called record_applied that calls recorder.record_applied but also keeps track of the calls so that a tearDown method could call recorder.record_unapplied as needed (and only if transactions aren't supported)?

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