Skip to content

Fix condition evaluation and user_answers when root_key is used#23

Merged
ericof merged 1 commit into
mainfrom
fix-root-key-conditions
May 22, 2026
Merged

Fix condition evaluation and user_answers when root_key is used#23
ericof merged 1 commit into
mainfrom
fix-root-key-conditions

Conversation

@erral
Copy link
Copy Markdown
Member

@erral erral commented May 22, 2026

Found a bug in Form.is_active and Form.user_answers where they were not aware of root_key nesting.
When a root_key is defined (like cookiecutter in cookieplone), all answers are nested under that key.
The engine was looking for answers at the top level, causing all conditions to fail and user_answers to be empty or raise KeyError.

This PR:

  • Makes is_active look inside root_key for gating answers.
  • Makes user_answers retrieve values from the nested dict.
  • Updates BaseRenderer.render to automatically record un-nested initial_answers under the root_key if one exists.
  • Adds regression tests in tests/form/test_form_root_key.py.

This is required for conditional questions in cookieplone to work properly.

@ericof ericof merged commit 46b2b92 into main May 22, 2026
10 of 11 checks passed
@ericof ericof deleted the fix-root-key-conditions branch May 22, 2026 13:43
ericof pushed a commit that referenced this pull request May 22, 2026
ericof pushed a commit that referenced this pull request May 22, 2026
* Remove debug log messages

* Refactor BaseRenderer.render to reduce complexity

* Linting fixes

* Add news fragments for PRs #23 and #24

---------

Co-authored-by: Érico Andrei <ericof@plone.org>
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.

2 participants