(core) Add PEEK() function to bypass circular dependencies

Summary:
Adds a Python function `PEEK()` for use in formulas which temporarily sets a new attribute `Engine._peeking` which disables the `_use_node` method, preventing dependency tracking and allowing the given expression to use outdated values. This allows circumventing circular reference errors. It's particularly meant for trigger formulas although it works in normal formulas as well. The expression is wrapped in a `lambda` by `codebuilder` for lazy evaluation.

Discussion: https://grist.slack.com/archives/C0234CPPXPA/p1653571024031359

Test Plan: Added a Python unit test for circular trigger formulas using PEEK.

Reviewers: dsagal

Reviewed By: dsagal

Subscribers: paulfitz

Differential Revision: https://phab.getgrist.com/D3453
This commit is contained in:
Alex Hall
2022-06-02 16:24:41 +02:00
parent f837f43e55
commit c5ebd7db3d
4 changed files with 95 additions and 0 deletions

View File

@@ -19,6 +19,7 @@ LAZY_ARG_FUNCTIONS = {
'ISERR': slice(0, 1),
'ISERROR': slice(0, 1),
'IFERROR': slice(0, 1),
'PEEK': slice(0, 1),
}
def make_formula_body(formula, default_value, assoc_value=None):