Opened 4 years ago

Closed 4 years ago

#31413 closed Bug (fixed)

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

Reported by: Tim Graham Owned by: Hasan Ramezani
Component: Migrations Version: 3.0
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes 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 (9)

comment:1 by Mariusz Felisiak, 4 years ago

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 by Sanskar Jaiswal, 4 years ago

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 by Tim Graham, 4 years ago

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

comment:4 by Sanskar Jaiswal, 4 years ago

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 by Tim Graham, 4 years ago

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)?

comment:6 by Hasan Ramezani, 4 years ago

Owner: changed from nobody to Hasan Ramezani
Status: newassigned

comment:7 by Hasan Ramezani, 4 years ago

Has patch: set

comment:8 by Mariusz Felisiak, 4 years ago

Triage Stage: AcceptedReady for checkin

comment:9 by Mariusz Felisiak <felisiak.mariusz@…>, 4 years ago

Resolution: fixed
Status: assignedclosed

In a2e3f95b:

Fixed #31413 -- Fixed isolation of migrations.test_loader on databases that don't support transactions.

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