[17.0][IMP] kpi: add _get_eval_context hook#1177
Open
miquelrosell99 wants to merge 1 commit into
Open
Conversation
Extracts the safe_eval context into a dedicated method so other modules can extend it without overriding the whole _get_kpi_value method. This makes the KPI engine more extensible for custom safe-eval globals.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR introduces a
_get_eval_contexthook on thekpimodel.Currently, any module that wants to inject additional safe globals into Python KPI formulas has to override the entire
_get_kpi_valuemethod. This is fragile and duplicates core logic.By extracting the safe_eval context into a dedicated method, other modules can simply inherit from
kpiand override_get_eval_contextto add their own helpers (e.g.dateutil,mean, domain-specific functions).Changes:
kpi._get_eval_context()returning the default context.self._get_eval_context()inside_get_kpi_valuefor Python KPIs.selfanddatetime, and that it is used during KPI evaluation.