Ticket #34420: patch.patch

File patch.patch, 1.7 KB (added by Andy Chosak, 20 months ago)
  • django/db/migrations/writer.py

    diff --git a/django/db/migrations/writer.py b/django/db/migrations/writer.py
    index a59f0c8dcb..f0eb4d2dc1 100644
    a b class MigrationWriter:  
    175175
    176176        # Sort imports by the package / module to be imported (the part after
    177177        # "from" in "from ... import ..." or after "import" in "import ...").
    178         sorted_imports = sorted(imports, key=lambda i: i.split()[1])
     178        sorted_imports = sorted(
     179            imports, key=lambda i: (i.split()[0] == "from", i.split()[1])
     180        )
    179181        items["imports"] = "\n".join(sorted_imports) + "\n" if imports else ""
    180182        if migration_imports:
    181183            items["imports"] += (
  • tests/migrations/test_writer.py

    diff --git a/tests/migrations/test_writer.py b/tests/migrations/test_writer.py
    index 1c11c68e97..c6638b3083 100644
    a b import os  
    77import pathlib
    88import re
    99import sys
     10import time
    1011import uuid
    1112import zoneinfo
    1213from types import NoneType
    class WriterTests(SimpleTestCase):  
    912913                            ),
    913914                        ),
    914915                    ),
     916                    migrations.AddField(
     917                        "mymodel",
     918                        "myfield2",
     919                        models.FloatField(default=time.time),
     920                    ),
    915921                ]
    916922            },
    917923        )
    918924        writer = MigrationWriter(migration)
    919925        output = writer.as_string()
    920926        self.assertIn(
    921             "import datetime\nfrom django.db import migrations, models\n",
     927            "import datetime\nimport time\nfrom django.db import migrations, models\n",
    922928            output,
    923929        )
    924930
Back to Top