1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Fixed #31499 -- Stored ModelState.fields into a dict.

This allows the removal of its O(n) .get_field_by_name method and many
other awkward access patterns.

While fields were initially stored in a list to preserve the initial
model definiton field ordering the auto-detector doesn't take field
ordering into account and no operations exists to reorder fields of a
model.

This makes the preservation of the field ordering completely superflous
because field reorganization after the creation of the model state
wouldn't be taken into account.
This commit is contained in:
Simon Charette
2020-04-21 23:14:34 -04:00
committed by Mariusz Felisiak
parent 696024fb73
commit 06889d6206
9 changed files with 104 additions and 112 deletions

View File

@@ -73,15 +73,12 @@ class LoaderTests(TestCase):
author_state = project_state.models["migrations", "author"]
self.assertEqual(
[x for x, y in author_state.fields],
list(author_state.fields),
["id", "name", "slug", "age", "rating"]
)
book_state = project_state.models["migrations", "book"]
self.assertEqual(
[x for x, y in book_state.fields],
["id", "author"]
)
self.assertEqual(list(book_state.fields), ['id', 'author'])
# Ensure we've included unmigrated apps in there too
self.assertIn("basic", project_state.real_apps)
@@ -122,10 +119,7 @@ class LoaderTests(TestCase):
self.assertEqual(len([m for a, m in project_state.models if a == "migrations"]), 1)
book_state = project_state.models["migrations", "book"]
self.assertEqual(
[x for x, y in book_state.fields],
["id", "user"]
)
self.assertEqual(list(book_state.fields), ['id', 'user'])
@override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations_run_before"})
def test_run_before(self):