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

@ -516,13 +516,13 @@ class ExecutorTests(MigrationTestBase):
state = executor.migrate([
('mutate_state_a', '0001_initial'),
])
self.assertIn('added', dict(state.models['mutate_state_b', 'b'].fields))
self.assertIn('added', state.models['mutate_state_b', 'b'].fields)
executor.loader.build_graph()
# Migrate backward.
state = executor.migrate([
('mutate_state_a', None),
])
self.assertIn('added', dict(state.models['mutate_state_b', 'b'].fields))
self.assertIn('added', state.models['mutate_state_b', 'b'].fields)
executor.migrate([
('mutate_state_b', None),
])