Allow ConditionField to reflect dynamically-added condition choices.
Review Request #14279 — Created Dec. 18, 2024 and updated
The Conditions system was designed with the intent that conditions could
be dynamically registered and unregistered as needed, offering
extensibility in the types of condition choices presented and processed.This was never tested until now, and we've found a few flaws. One of
those is thatConditionField
was calculating the valid choices at
field definition time, and held on to that when copying for a new form
instance. The choices present initially would remain present, and we'd
never recalculate.To work around this, we now defer any processing of choices until we
need them, and we always refer back to theConditionSet
provided at
the latest initialization time (such as when initializing fields for a
form instance).We remember the initial choices provided to the field and to the widget,
and refer back to that whenever we need to start fresh. If this is a
class, it's instantiated as late as possible. Same if it's a callback
providing an instance. This state is never deep-copied over to a new
field, allowing new instances to reflect the available choices at that
moment in time.
ConditionsWidget
is now the source of truth for the condition choices.
ConditionsField
has a wrapper that forwards on to that one. This
simplifies lifecycles considerably.To take full advantage of this, callers should pass in an instance and
not a class when caling the field.There's also one fix in here for managing widgets. We were accessing
the value field'swidget
attribute, which didn't exist. Initially,
this code was built to work with form fields, but we moved to a wrapper
class. We now define a forwarding attribute to get the inner field's
widget.
Unit tests pass.
Tested this with other in-progress work for more dynamic condition
choices. Verified that I could enable an extension and see all the
choices.
Summary | ID |
---|---|
6544d8f2cf61d4c35514d56c5c541fc337aa5fe9 |
Description | From | Last Updated |
---|---|---|
line too long (88 > 79 characters) Column: 80 Error code: E501 |
reviewbot | |
redefinition of unused 'Self' from line 11 Column: 1 Error code: F811 |
reviewbot | |
More and more throughout the python ecosystem I'm seeing that setters are documented like regular methods ("Set the condition choices...") … |
david | |
Can you add a module docstring? |
david |