#37018: Generated migrations should use tuples instead of lists
-------------------------------------+-------------------------------------
     Reporter:  Daniel Quinn         |                     Type:
                                     |  Cleanup/optimization
       Status:  new                  |                Component:
                                     |  Migrations
      Version:  6.0                  |                 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
-------------------------------------+-------------------------------------
 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 ([https://docs.astral.sh/ruff/ ruff]) which I think rightly
 [https://docs.astral.sh/ruff/rules/mutable-class-default/ 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
 
[https://github.com/django/django/blob/main/django/db/migrations/writer.py#L311-L323
 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.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/37018>
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 [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/0107019d48cf3b37-47e0e0fa-e163-4eb2-afc5-0ff90a21af78-000000%40eu-central-1.amazonses.com.

Reply via email to