[Django] #35711: Running migrate with disabled migrations fails with version 5.1

14 views
Skip to first unread message

Django

unread,
Aug 27, 2024, 11:59:44 AM8/27/24
to django-...@googlegroups.com
#35711: Running migrate with disabled migrations fails with version 5.1
------------------------+--------------------------------------
Reporter: Mounir | Type: Bug
Status: new | Component: Migrations
Version: 5.1 | Severity: Normal
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------+--------------------------------------
For some tests I run the migrate with the --run-syncdb

Since the update to 5.1 (from 5.0) I get this error:


{{{
Operations to perform:
Apply all migrations: (none)
Running migrations:
No migrations to apply.
Traceback (most recent call last):
File "/app/./manage.py", line 30, in <module>
main()
File "/app/./manage.py", line 26, in main
execute_from_command_line(sys.argv)
File "/home/app/venv/lib/python3.12/site-
packages/django/core/management/__init__.py", line 442, in
execute_from_command_line
utility.execute()
File "/home/app/venv/lib/python3.12/site-
packages/django/core/management/__init__.py", line 436, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/app/venv/lib/python3.12/site-
packages/django/core/management/base.py", line 413, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/app/venv/lib/python3.12/site-
packages/django/core/management/base.py", line 459, in execute
output = self.handle(*args, **options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/core/management/commands/migrate.py", line 21, in handle
super().handle(*args, **options)
File "/home/app/venv/lib/python3.12/site-
packages/django/core/management/base.py", line 107, in wrapper
res = handle_func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/app/venv/lib/python3.12/site-
packages/django/core/management/commands/migrate.py", line 336, in handle
changes = autodetector.changes(graph=executor.loader.graph)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/app/venv/lib/python3.12/site-
packages/django/db/migrations/autodetector.py", line 67, in changes
changes = self._detect_changes(convert_apps, graph)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/app/venv/lib/python3.12/site-
packages/pgtrigger/migrations.py", line 156, in _detect_changes
return super()._detect_changes(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/app/venv/lib/python3.12/site-
packages/django/db/migrations/autodetector.py", line 224, in
_detect_changes
self._sort_migrations()
File "/home/app/venv/lib/python3.12/site-
packages/django/db/migrations/autodetector.py", line 426, in
_sort_migrations
dep = self._resolve_dependency(dep)[0]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/app/venv/lib/python3.12/site-
packages/django/db/migrations/autodetector.py", line 279, in
_resolve_dependency
if dependency.app_label != "__setting__":
^^^^^^^^^^^^^^^^^^^^
AttributeError: 'tuple' object has no attribute 'app_label'
}}}

The disabling of migrations is done with the help of migration modules
setting:

{{{
class DisableMigrations:
def __contains__(self, item):
return True

def __getitem__(self, item):
return None

MIGRATION_MODULES = DisableMigrations()
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/35711>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Aug 27, 2024, 12:02:47 PM8/27/24
to django-...@googlegroups.com
#35711: Running migrate with disabled migrations fails with version 5.1
----------------------------+--------------------------------------
Reporter: Mounir | Owner: (none)
Type: Bug | Status: new
Component: Migrations | Version: 5.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------------------------
Description changed by Mounir:

Old description:
New description:
Possible regression from
https://github.com/django/django/commit/7dd3e694db17bc34f9ce73e516f853ebd16e19e7

--
--
Ticket URL: <https://code.djangoproject.com/ticket/35711#comment:1>

Django

unread,
Aug 27, 2024, 1:38:44 PM8/27/24
to django-...@googlegroups.com
#35711: Running migrate with disabled migrations fails with version 5.1
----------------------------+--------------------------------------
Reporter: Mounir | Owner: (none)
Type: Bug | Status: closed
Component: Migrations | Version: 5.1
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------------------------
Changes (by Simon Charette):

* resolution: => invalid
* status: new => closed

Comment:

Setting `MIGRATION_MODULES = DisableMigrations()` is not a supported
pattern.

I assume you ported it over from ticket:25388#comment:20 which eventually
resulted in the addition of the `TEST["MIGRATE"]`
[https://docs.djangoproject.com/en/5.1/ref/settings/#migrate setting]
which should now be used instead.

Please re-open if you can reproduce without using the `DisableMigrations`
pattern.
--
Ticket URL: <https://code.djangoproject.com/ticket/35711#comment:2>

Django

unread,
Aug 28, 2024, 3:18:43 AM8/28/24
to django-...@googlegroups.com
#35711: Running migrate with disabled migrations fails with version 5.1
----------------------------+--------------------------------------
Reporter: Mounir | Owner: (none)
Type: Bug | Status: closed
Component: Migrations | Version: 5.1
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------------------------
Comment (by Mounir):

Based from Django's docs:

When you supply None as a value for an app, Django will consider the
app as an app without migrations regardless of an existing migrations
submodule. This can be used, for example, in a test settings file to skip
migrations while testing (tables will still be created for the apps’
models). To disable migrations for all apps during tests, you can set the
MIGRATE to False instead. If MIGRATION_MODULES is used in your general
project settings, remember to use the migrate --run-syncdb option if you
want to create tables for the app.


So, when I tried to set MIGRATION_MODULES for each app to None (without
the `DisableMigrations` pattern) I still get the same error.
Background: I used this approach before running some e2e tests, which run
Django in a normal mode, disabling migrations helps speeding up the
process.
--
Ticket URL: <https://code.djangoproject.com/ticket/35711#comment:3>

Django

unread,
Aug 28, 2024, 9:13:39 AM8/28/24
to django-...@googlegroups.com
#35711: Running migrate with disabled migrations fails with version 5.1
----------------------------+--------------------------------------
Reporter: Mounir | Owner: (none)
Type: Bug | Status: closed
Component: Migrations | Version: 5.1
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------------------------
Comment (by Simon Charette):

I created a new project using 5.1, assigned `None` to each entry in
`MIGRATION_MODULES`, and ran `migrate --run-syncdb` without any issues.

You might have to provide a project that reproduces I'm afraid as I
audited the entire autodetector modue for `add_operation` calls passing
`dependencies` (which are the ones adding `_auto_deps`) and also used type
checking and found no violations. At this point I suspect you might use a
third-party app that overrides the `migrate` management command.
--
Ticket URL: <https://code.djangoproject.com/ticket/35711#comment:4>

Django

unread,
Aug 28, 2024, 9:35:51 AM8/28/24
to django-...@googlegroups.com
#35711: Running migrate with disabled migrations fails with version 5.1
----------------------------+--------------------------------------
Reporter: Mounir | Owner: (none)
Type: Bug | Status: closed
Component: Migrations | Version: 5.1
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------------------------
Comment (by Mounir):

If it helps, this is the value causing the issue which get passed as
dependency parameters: ('audit_log', 'requestauditlog', 'content_type',
True)

Maybe it's only the case when using the contenttype framework:

{{{
content_type = models.ForeignKey(
ContentType,
on_delete=models.CASCADE,
verbose_name=_('Content type'),
blank=True,
null=True,
)
object_id = models.PositiveBigIntegerField(
verbose_name=_('Object ID'),
help_text=_('ID of the object to link'),
blank=True,
null=True,
)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/35711#comment:5>

Django

unread,
Aug 28, 2024, 9:48:37 AM8/28/24
to django-...@googlegroups.com
#35711: Running migrate with disabled migrations fails with version 5.1
----------------------------+--------------------------------------
Reporter: Mounir | Owner: (none)
Type: Bug | Status: closed
Component: Migrations | Version: 5.1
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------------------------
Comment (by Mounir):

Ok the issue comes from django-pgtrigger, the latest version fixes the
operations list and this seems to work.

I'm sorry for the inconvenience, thanks for your help, much appreciated.
--
Ticket URL: <https://code.djangoproject.com/ticket/35711#comment:6>

Django

unread,
Aug 28, 2024, 10:08:57 AM8/28/24
to django-...@googlegroups.com
#35711: Running migrate with disabled migrations fails with version 5.1
----------------------------+--------------------------------------
Reporter: Mounir | Owner: (none)
Type: Bug | Status: closed
Component: Migrations | Version: 5.1
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------------------------
Comment (by Simon Charette):

[https://github.com/Opus10/django-
pgtrigger/commit/13dea27d9e76a45128ef3836f0f9ab8f2ce4cd75 This is the
commit resolving the problem for the record].
--
Ticket URL: <https://code.djangoproject.com/ticket/35711#comment:7>
Reply all
Reply to author
Forward
0 new messages