Skip to content

fix(rex): don't expose failed env lookups in the env mapping - #2169

Open
Sanjays2402 wants to merge 2 commits into
AcademySoftwareFoundation:mainfrom
Sanjays2402:fix/env-undefined-var-leak
Open

fix(rex): don't expose failed env lookups in the env mapping#2169
Sanjays2402 wants to merge 2 commits into
AcademySoftwareFoundation:mainfrom
Sanjays2402:fix/env-undefined-var-leak

Conversation

@Sanjays2402

Copy link
Copy Markdown

Closes #2039

Accessing an undefined variable via env.FOO raises RexUndefinedVariableError (expected, catchable), but EnvironmentDict.__getitem__ caches an EnvironmentVariable for that name anyway. A later env.values()/iteration — typically from an unrelated package resolved afterwards — resolves the cached name and raises a second RexUndefinedVariableError, failing the whole resolve.

The mapping methods now filter out names that are not actually defined, so a failed lookup leaves no trace; setting the variable later makes it visible again. New test_11 in test_rex.py fails on main with the reported error and passes with the fix.

Accessing an undefined variable via env.FOO raises RexUndefinedVariableError,
but EnvironmentDict.__getitem__ caches an EnvironmentVariable for that name
regardless. A later env.values()/iteration - typically from an unrelated
package resolved afterwards - then resolves that cached name and raises a
second RexUndefinedVariableError, failing the whole resolve.

Filter undefined names out of keys()/__iter__/__len__/__contains__ so the
mapping interface only exposes variables that actually exist. Setting the
variable later makes it visible again.

Adds a regression test covering keys/values/len/contains after a failed
lookup.

Signed-off-by: Sanjay Santhanam <51058514+Sanjays2402@users.noreply.github.com>
@Sanjays2402
Sanjays2402 requested a review from a team as a code owner July 25, 2026 22:51
@linux-foundation-easycla

linux-foundation-easycla Bot commented Jul 25, 2026

Copy link
Copy Markdown

CLA Not Signed

@maxnbk

maxnbk commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Hello, thanks for the PR submission. We'd like to see CLA's signed before reviewing if possible, because if the CLA is unable to be signed, we are unable to accept the contribution. Hope you understand.

@JeanChristopheMorinPerso JeanChristopheMorinPerso added the Blocked by CLA Waiting on CLA to be signed label Aug 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Blocked by CLA Waiting on CLA to be signed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Accessing undefined env variable causes side-effect in unrelated package

3 participants