#33022: main-random test failures (build #8):
field_deconstruction.tests.FieldDeconstructionTests and
migrations.test_commands.MigrateTests
--------------------------------+------------------------------------
     Reporter:  Chris Jerdonek  |                    Owner:  nobody
         Type:  Bug             |                   Status:  new
    Component:  Migrations      |                  Version:  dev
     Severity:  Normal          |               Resolution:
     Keywords:                  |             Triage Stage:  Accepted
    Has patch:  0               |      Needs documentation:  0
  Needs tests:  0               |  Patch needs improvement:  0
Easy pickings:  0               |                    UI/UX:  0
--------------------------------+------------------------------------

Comment (by Jacob Walls):

 Reiterating from above PR:

 The pair of migrations tests that produces a failure is:
 - `test_custom_user`
 - `test_migrate_partially_applied_squashed_migration`

 Can be produced with:
 {{{
 ./tests/runtests.py migrations.test_commands.MigrateTests
 migrations.test_executor.ExecutorTests -k test_custom_user -k
 test_migrate_partially --shuffle 1022528553
 }}}

 The failure occurs during the `migrate` (to zero) command in the `finally`
 block with:

 {{{
     raise ValueError("\n".join(error.msg for error in errors))
 ValueError: The field migrations.Book.author was declared with a lazy
 reference to 'auth.user', but app 'auth' isn't installed.
 }}}

 `test_custom_user` overrides the `AUTH_USER_MODEL` setting like so:
 {{{
         AUTH_USER_MODEL="migrations.Author",
 }}}

 [https://docs.djangoproject.com/en/3.2/topics/auth/customizing/#changing-
 to-a-custom-user-model-mid-project Documentation] for the setting says
 that it's cumbersome to change this after migrations have been made:

 > Changing AUTH_USER_MODEL after you’ve created database tables is
 significantly more difficult since it affects foreign keys and many-to-
 many relationships, for example. This change can’t be done automatically
 and requires manually fixing your schema, moving your data from the old
 user table, and possibly manually reapplying some migrations. See #25313
 for an outline of the steps.

 This makes sense, because in the ordinary test execution order, the
 squashed migration in `test_migrate_partially_applied_squashed_migration `
 creates a `Book.Author` field like this:

 `                ('author', models.ForeignKey(null=True,
 on_delete=django.db.models.deletion.SET_NULL, to='migrations.author')),`

 But in the failing test order, instead creates this:

 `                ('author', models.ForeignKey(null=True,
 on_delete=django.db.models.deletion.SET_NULL,
 to=settings.AUTH_USER_MODEL)),`

 Since the documentation mentions this is cumbersome to address, the
 thought in the PR was just to keep all tests running on the app
 "migrations" with the same `AUTH_USER_MODEL`, but if that's not
 satisfactory, is the idea that we should rewrite
 `test_migrate_partially_applied_squashed_migration` to use a different app
 to run the test cases? Otherwise I'm not sure how to prevent
 `squashmigrations` from picking up the swappable user model.

 Thanks, and happy to keep digging if helpful.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/33022#comment:9>
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 django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/067.371e578bda0b83920ef923f240ef2ce2%40djangoproject.com.

Reply via email to