Skip to content

[#5958] Add support for logic rules in v3 Form serializer - #6490

Open
vaszig wants to merge 2 commits into
mainfrom
task/5958-add-support-for-logic-rules-in-api-v3
Open

[#5958] Add support for logic rules in v3 Form serializer#6490
vaszig wants to merge 2 commits into
mainfrom
task/5958-add-support-for-logic-rules-in-api-v3

Conversation

@vaszig

@vaszig vaszig commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Closes #5958

Changes

  • Add new field logic_rules to the new v3 form endpoint
  • Add validation concerning the logic rules and actions
  • Add tests

Checklist

Check off the items that are completed or not relevant.

  • Impact on features

    • Checked copying a form
    • Checked import/export of a form
    • Config checks in the configuration overview admin page
    • Checked new model fields are usable in the admin
    • Problem detection in the admin email digest is handled
  • Dockerfile/scripts

    • Updated the Dockerfile with the necessary scripts from the ./bin folder
  • Commit hygiene

    • Commit messages refer to the relevant Github issue
    • Commit messages explain the "why" of change, not the how
  • Documentation

    • Added documentation which describes the changes

@vaszig
vaszig marked this pull request as draft July 24, 2026 14:37
@vaszig
vaszig force-pushed the task/5958-add-support-for-logic-rules-in-api-v3 branch from 836a8de to 647da1c Compare July 27, 2026 10:53
@vaszig
vaszig marked this pull request as ready for review July 27, 2026 10:53
@codecov

codecov Bot commented Jul 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.59036% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.23%. Comparing base (0bbb02f) to head (9a5df6d).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
src/openforms/forms/api/v3/serializers/form.py 95.18% 1 Missing and 3 partials ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@vaszig
vaszig requested a review from sergei-maertens July 27, 2026 12:47

@sergei-maertens sergei-maertens left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 :-)

Comment thread src/openforms/forms/api/v3/typing.py Outdated
Comment thread src/openforms/forms/api/v3/typing.py Outdated
Comment thread src/openforms/forms/tests/v3/test_endpoints.py Outdated
Comment thread src/openforms/forms/tests/v3/test_endpoints.py Outdated
Comment thread src/openforms/forms/tests/v3/test_endpoints.py Outdated
Comment thread src/openforms/forms/api/v3/serializers/form.py Outdated
Comment thread src/openforms/forms/api/v3/serializers/form.py Outdated
Comment thread src/openforms/forms/api/v3/serializers/form.py Outdated
"type": {"validators": [RequireAppointmentsPlugin()]},
}

def _validate_actions(self, form: Form, temp_rules_instances: dict[FormLogic, int]):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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): {
                                            ...
                                        }
                                    }
                                }
                            }

Comment on lines +365 to +367
first_step: FormStep = min(
form.form_step_map.values(), key=lambda step: step.order
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

vaszig added 2 commits July 29, 2026 16:24
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.
@vaszig
vaszig force-pushed the task/5958-add-support-for-logic-rules-in-api-v3 branch from d47cd40 to 9a5df6d Compare July 29, 2026 14:24
@sergei-maertens sergei-maertens self-assigned this Jul 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for logic rules

2 participants