mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(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:
@@ -177,6 +177,9 @@ class Engine(object):
|
||||
# on any of these cells implies a circular dependency.
|
||||
self._locked_cells = set()
|
||||
|
||||
# Set to True by the PEEK() function to temporarily disable dependency tracking
|
||||
self._peeking = False
|
||||
|
||||
# The lists of actions of different kinds, built up while applying an action.
|
||||
self.out_actions = action_obj.ActionGroup()
|
||||
|
||||
@@ -474,6 +477,9 @@ class Engine(object):
|
||||
# This is used whenever a formula accesses any part of any record. It's hot code, and
|
||||
# it's worth optimizing.
|
||||
|
||||
if self._peeking:
|
||||
return
|
||||
|
||||
if self._current_node:
|
||||
# Add an edge to indicate that the node being computed depends on the node passed in.
|
||||
# Note that during evaluation, we only *add* dependencies. We *remove* them by clearing them
|
||||
|
||||
Reference in New Issue
Block a user