Opened 5 weeks ago

Last modified 4 weeks ago

#35656 assigned New feature

Make migration Command doesn't allow changing the autodetector

Reported by: Ahmed Ibrahim Owned by: leondaz
Component: Migrations Version: dev
Severity: Normal Keywords: migrations, makemigrations, commands
Cc: Ahmed Ibrahim Triage Stage: Accepted
Has patch: yes Needs documentation: yes
Needs tests: yes Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

I had a situation where I want to subclass the Autodetector to add more operations that the ones in Django, an operation that does not create a row, but rather, a table (different model)

This line is copied from django/django/core/management/commands/makemigrations.py

# Detect changes
changes = autodetector.changes(
     graph=loader.graph,
     trim_to_apps=app_labels or None,
     convert_apps=app_labels or None,
     migration_name=self.migration_name,
)

The suggested approach is to save the autodetector on the class level, and subclasses can override it to use their custom version.

P.S: I'm not sure if this is considered a feature or an optimization

Change History (7)

comment:1 by Ahmed Ibrahim, 5 weeks ago

Needs documentation: set

comment:2 by Ahmed Ibrahim, 5 weeks ago

Needs documentation: unset

comment:3 by Claude Paroz, 5 weeks ago

Easy pickings: unset
Triage Stage: UnreviewedAccepted
Version: dev

I also do think having a way to specify a custom autodetector class would be an improvement. However, the autodetector class should be the same in makemigrations as the one in migrate command, so it might not be trivial to define it so it doesn't require the user to customize the class separately in both commands.

in reply to:  3 ; comment:4 by Ahmed Ibrahim, 5 weeks ago

Replying to Claude Paroz:

I also do think having a way to specify a custom autodetector class would be an improvement. However, the autodetector class should be the same in makemigrations as the one in migrate command, so it might not be trivial to define it so it doesn't require the user to customize the class separately in both commands.

Thank you my friend for accepting the ticket and also stating the difficulty of the ticket, yes it bumped up a bit, I will do my best and mention the pr so that you may have a look if you don't mind

comment:5 by Ahmed Ibrahim, 5 weeks ago

Has patch: set

comment:7 by Sarah Boyce, 4 weeks ago

Needs documentation: set
Needs tests: set
Patch needs improvement: set
Type: Cleanup/optimizationNew feature

Marking as a new feature as we should highlight this change in the docs/release notes for people to use it. It also should have tests

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