Introduce a top-level concept of a simulation.
Review Request #9539 — Created Jan. 25, 2018 and submitted
Mutation simulations are an integral part of Django Evolution. They're
responsible for validating that a mutation can be performed against part
of a database signature, and modifying that signature for storage. The
way they worked before is that each mutation had asimulate()
method
that took in several pieces of state, and it was the responsibility of
the method to look up data (and handle errors during lookup) from the
signatures and, if necessary, raise aSimulationFailure
if the
simulation could not be applied.This change formalizes some of this process and simplifies the work
required in thesimulate()
methods. There's now a top-level
Simulation
class, which olds all the state for a simulation, provides
helpful accessors for getting parts of the signature (raising errors if
not found), and providing a way to fail a simulation.Each mutation now has a standard error message describing a simulation
failure for that mutation, which is called when failing the simulation.
This can reference variables on the class or from calls to
Simulation.fail
.Each mutation's
simulate()
method takes only aSimulation
and no
other state, and can use that to look up the signatures. Since they no
longer have to handle signature-related lookup failures, each mutation
is now a bit smaller than it was when the improved error messages were
introduced.Speaking of error messages, now that we have a standard way of failing a
simulation, the remaining error messages now provide detailed context,
helping to debug problems when a mutation fails.In order to benefit
SQLMutation
, itsupdate_func
(which is needed to
do a simulation and update the signature) can now take either a legacy
app_label, project_sig
argument, or a new-styleSimulation
. Newer
evolution files should use the latter.
Unit tests pass.
- Change Summary:
-
Fixed some line length issues.
- Commit:
-
35b8362183ed02f0e3a948f65b9f89e4b50cb620753651b1282587b3fc75021ef451c874e8346878
- Diff:
-
Revision 2 (+440 -399)
Checks run (2 succeeded)
- Change Summary:
-
Fixled bad up the english.
- Commit:
-
753651b1282587b3fc75021ef451c874e8346878755e55371da66126b7a27d9005281056b2389572
- Diff:
-
Revision 3 (+440 -399)