Opened 3 weeks ago

Closed 3 weeks ago

#37018 closed Cleanup/optimization (wontfix)

Generated migrations should use tuples instead of lists

Reported by: Daniel Quinn Owned by:
Component: Migrations Version: 6.0
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When running makemigrations, the typical output contains a Migration class with at least two attributes: dependencies and operations, both of which are mutable lists rather than immutable tuples. This upsets my linter (ruff) which I think rightly complains that we've got a class here with mutable default values:

error[RUF012]: Mutable default value for class attribute
  --> plugins/generic_to_clickhouse/migrations/0001_initial.py:13:20
   |
11 |     initial = True
12 |
13 |     dependencies = []
   |                    ^^
14 |
15 |     operations = (
   |
help: Consider initializing in `__init__` or annotating with `typing.ClassVar`

Digging through the source, I see that this is just the result of a hard-coded template using [ instead of (, so I have to assume that a fix would be pretty straightforward.

So unless there's a reason we want these values to be mutable, I'm happy to do this work. I just don't want to do the work and have it rejected for unforseen reasons.

Change History (1)

comment:1 by Sarah Boyce, 3 weeks ago

Resolution: wontfix
Status: newclosed

Hi Daniel! Thank you for the ticket
Unfortunately I think this would be a breaking change. If folks expect dependencies to be a list, then they can append/extend the list.
I believe we do this inside MigrationAutodetector._optimize_migrations() for example and it is likely that other third party apps might be doing similar things
This change would then need a deprecation path and I am not sure it is worth the effort

If this is something you have considered and you have a plan for this, feel free to reopen the ticket for another review

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