Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Complex jexl issues (refactor(forms): rewrite structure and jexl evaluator) #2356

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

winged
Copy link
Contributor

@winged winged commented Jan 14, 2025

refactor(forms): rewrite structure and jexl evaluator

The new structure / jexl evaluator works a bit differently: Instead of
trying to replace evaluation contexts during recursive evaluation (for
example is_hidden checks), we now have a local JEXL runtime for each
field. Also, the JEXL expressions (or their results, rather) are heavily
cached and should speed things up significantly.

Regarding the test cases:

We're trying to keep the test cases' meaning 100% unchanged - the only
modifications currently are some improved assertion messages, so
debugging becomes easier, as well as refactoring some for better readability.

Some tests are extended, and some are now better documented, to cover
more aspects and explain in more detail what our assumptions and
expectations actually are.

BREAKING CHANGE: Code that uses the form jexl and / or structure code
most likely will need to be rewritten. The changes are small-ish, but
still semantically not exactly equal.

refactor: rewrite the calculated-question code to use the new structure

The whole updating code for calculated fields was rather complex and
had quite a few subtle bugs. With the new structure, we have infrastructure
in place to build the same behaviour in a much better, more reliable way.

@winged winged force-pushed the complex_jexl_issues branch 3 times, most recently from 54e63bd to 2007067 Compare January 24, 2025 14:56
@winged winged force-pushed the complex_jexl_issues branch 13 times, most recently from c7a91d0 to 15ea4c2 Compare February 18, 2025 15:13
winged and others added 6 commits February 18, 2025 16:15
Table rows were sorted, but backwards; questions were not sorted at all,
and thus might have lead to unpredictable behaviour. We noe explicitly
sort this correctly, therefore making things a bit more testable.
Calculated questions do not work correctly when located inside a table row:
The recalculation is currently triggered on the root document, which will
only find one of the rows, and update that - while likely ignoring the row
where the actual dependency is located.

This test is intended to demonstrate the problem, and thus will currently
fail.
The new structure / jexl evaluator works a bit differently: Instead of
trying to replace evaluation contexts during recursive evaluation (for
example `is_hidden` checks), we now have a local JEXL runtime for each
field. Also, the JEXL expressions (or their results, rather) are heavily
cached and should speed things up significantly.

Test cases:

We're trying to keep the test cases' meaning 100% unchanged - the only
modifications currently are some improved assertion messages, so
debugging becomes easier, as well as refactoring some for better readability.

Some tests are extended, and some are now better documented, to cover
more aspects and explain in more detail what our assumptions and
expectations actually are.

BREAKING CHANGE: Code that uses the form jexl and / or structure code
most likely will need to be rewritten. The changes are small-ish, but
still semantically not exactly equal.
The whole updating code for calculated fields was rather complex and
had quite a few subtle bugs. With the new structure, we have infrastructure
in place to build the same behaviour in a much better, more reliable way.

TODO: This is currently not yet fully optimized, and we're doing quite a few
more queries than before. Also TODO: A few issues were discovered that still
need to be addressed - namely calculated questions not attached to a root form.
@winged winged force-pushed the complex_jexl_issues branch from 15ea4c2 to 931f0f7 Compare February 18, 2025 15:15
@winged winged requested a review from open-dynaMIX February 18, 2025 15:17
@winged winged changed the title Fix: Complex jexl issues Fix: Complex jexl issues (refactor(forms): rewrite structure and jexl evaluator) Feb 18, 2025
@winged winged requested a review from czosel February 18, 2025 15:17
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