Skip to content

Fix engine reuse with 'with input.x as y' statement - #474

Merged
anakrish merged 1 commit into
microsoft:mainfrom
ZabelinK:fix-with-document-input
Sep 8, 2025
Merged

Fix engine reuse with 'with input.x as y' statement#474
anakrish merged 1 commit into
microsoft:mainfrom
ZabelinK:fix-with-document-input

Conversation

@ZabelinK

@ZabelinK ZabelinK commented Sep 4, 2025

Copy link
Copy Markdown
Contributor

This fix is suppose to solve the following issue

Consider the policy which has some 'with input.a as b' statement, if we try to reuse engine with this policy several times but with different input we will have an issue that during second evaluation with new input after interpreting 'with' statement we will overwrite input with input values from first evaluation. The reason is that self.with_document['input'] is used in interpretation of 'with' statement and it isn't updated in set_input and it isn't cleaned before second evaluation (because it was already prepared), in a result it keep input from first evaluation and each time policy does 'with as' it overwrite its full input.

I am not sure that this is the best way to fix it, it seems to me that it is better to remove 'input' from self.with_document and use only self.input where needed, so we keep it only in one place and also 'input' doesn't seems to be conceptually part of a document. But I just wanted to highlight the issue and provide the minimal fix.

@anakrish anakrish left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for thhe fix, @ZabelinK

@anakrish
anakrish merged commit 4ec9e76 into microsoft:main Sep 8, 2025
33 checks passed
@anakrish

anakrish commented Sep 8, 2025

Copy link
Copy Markdown
Collaborator

@ZabelinK Curious what your use of with is? I'm working on an intermediate (IL) based evaluator and the current thinking is to not support with since it is tricky to implement efficiently.

@ZabelinK

ZabelinK commented Sep 8, 2025

Copy link
Copy Markdown
Contributor Author

@anakrish
I wanted to do the following thing:

  1. Get some external data via extension call
  2. Use this data in incremental rule via input field overwrite

For example like this

allow := results if {
  external_data := extension_1(input.x)
  results := incremental_rule_y with input.z as external_data
}

incremental_rule_y contains result if {
   ... some work with input.z ...
}

incremental_rule_y contains result if {
   ... another work with input.z ...
}

Initially I wanted to create a proper function which will get external_data as argument, but it seems that it isn't possible to pass arguments to incremental rules. Maybe it is possible to do this in some other way, but this was a moment when I discovered this issue. And for our case we realized that it would be better to prefetch this external data before policy evaluation and pass them as part of an input, so I didn't try to find other ways to combine incrementral rules with some data received during policy evaluation.

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