fix: [SD_CFX_002] Add isNotPresent/isPresent suffix unary operators to LiquidJS computation engine - #48
Draft
sd-gh-bot wants to merge 1 commit into
Draft
Conversation
…o LiquidJS evalExp These operators are used in Liquid computation text (common_cf_text) across templates such as template 27188 (Metergy Solutions, Workspace 353009). They were already supported in docx-templater/expressions.js (Angular Expressions) but were silently unsupported in the LiquidJS computation engine, causing: RenderError: cannot eval 'sd_thermal_risk_type isNotPresent' as value, line:53 This only manifested at runtime when the guard condition resolving to a code path containing the isNotPresent expression evaluated to TRUE (e.g. Electricity Risk Type = Common Area), returning HTTP 400 from cfexporter and SD_CFX_002 to the UI. Changes: - evalExp: detect suffix unary operators before falling through to evalValue - validateExpression: same — prevents false validation failures - SUFFIX_UNARY_OPERATORS map: semantics aligned with docx-templater isPresent/isNotPresent (null | undefined | false → not present; anything else → present) - test/syntax.js: 10 new tests covering null, undefined, false, string, empty-string cases Fixes: SD_CFX_002 generation failure for contracts with Electricity Risk Type = Common Area Co-authored-by: Anjali Swami <vend-anjaliswami@spotdraft.com>
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.
User description
Problem
Contract generation fails with
SD_CFX_002when Electricity Risk Type = Common Area is selected in the Retrofit flow (e.g. Metergy Solutions, Workspace 353009, Contract SD-3014).Root cause
Template
common_cf_textuses{% if sd_thermal_risk_type isNotPresent %}inside a Liquid computation block. TheisNotPresentandisPresentoperators are registered indocx-templater/expressions.js(Angular Expressions) but were not recognised by the LiquidJS computation engine (@spotdraft/liquidjs). When the enclosing{% if ... == "Common Area" %}guard evaluated to TRUE, execution reached the unrecognised operator, throwing:This bubbled up as ComputationError -> cfexporter HTTP 400 -> SD_CFX_002.
Fix
Add
isNotPresentandisPresentas suffix unary operators tosrc/syntax.jsevalExp and validateExpression. Semantics match docx-templater/expressions.js. 10 new tests added; 23 pre-existing failures unchanged.Immediate mitigation (before deploy)
Data-fix Django shell script provided in incident report to unblock contract 1683267 (SD-3014) now.
Generated description
Below is a concise technical summary of the changes proposed in this PR:
Add suffix unary handling to the Liquid computation parser so
evalExpandvalidateExpressionrecognizeisNotPresent/isPresentand mirror docx-templater semantics in template text. Add unit coverage undertest/syntax.jsto assert the new operators respond correctly to null, undefined, false, and string values.syntax.jsevalExpandvalidateExpressionso Liquid computations supportisNotPresent/isPresentmatching docx-templater syntax for computation templates.Modified files (1)
Latest Contributors(2)
test/syntax.jsfor null, undefined, false, empty string, and populated values to ensure the new semantics work during evaluation.Modified files (1)
Latest Contributors(2)