[#5958] Add support for logic rules in v3 Form serializer - #6490
Conversation
836a8de to
647da1c
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6490 +/- ##
========================================
Coverage 97.22% 97.23%
========================================
Files 860 861 +1
Lines 33061 33223 +162
Branches 2999 3019 +20
========================================
+ Hits 32143 32303 +160
Misses 606 606
- Partials 312 314 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
sergei-maertens
left a comment
There was a problem hiding this comment.
Quite a number of remarks, but in general I think you managed this well - the current codebase doesn't allow for a much cleaner implementation :-)
| "type": {"validators": [RequireAppointmentsPlugin()]}, | ||
| } | ||
|
|
||
| def _validate_actions(self, form: Form, temp_rules_instances: dict[FormLogic, int]): |
There was a problem hiding this comment.
The implementation is quite visibly overloading and long (making it harder to review). I'd consider breaking out the various action-type specific validations into little helper functions and wire them up in this method with some pattern matching:
match action:
case {"type": LogicActionTypes.variable}:
...
case {"type": str(action_type)} if action_type in LOGIC_ACTION_TYPES_REQUIRING_COMPONENT:
errors = _check_component_action_definition(...)together with the collection of all errors, you can cut down on a lot of boilerplate and avoid repeating this block all the time as well:
"logic_rules": {
str(rule.order): {
"actions": {
str(action_index): {
...
}
}
}
}
| first_step: FormStep = min( | ||
| form.form_step_map.values(), key=lambda step: step.order | ||
| ) |
There was a problem hiding this comment.
there was a crash recently w/r to this kind of validation running for appointment forms or forms that didn't have any steps at all - this should now not happen anymore because we already have the earlier validation about the number of steps per component type, right?
There was a problem hiding this comment.
This is executed only if there are logic rules. If there are and we have no steps then we get an AssertionError from logic analysis (here I should put a default value of None which I forgot).
The ideal situation is to handle validations in the serializer's validate method. For some of the validations that need to take place (like the valid form steps and logic rules) we have to be able to access the form instance. This is not possible in the validate method (not existing yet) so we do that in the create and update methods. We can perform these in the validate method but we would then have to refactor a lot of code and this is not our goal for now.
d47cd40 to
9a5df6d
Compare
Closes #5958
Changes
logic_rulesto the new v3 form endpointChecklist
Check off the items that are completed or not relevant.
Impact on features
Dockerfile/scripts
./binfolderCommit hygiene
Documentation