Skip to content

Select: preserve context (incl. _params) when building subcons - #1194

Open
DresdenGman wants to merge 1 commit into
construct:masterfrom
DresdenGman:fix-1038-select-params
Open

DresdenGman wants to merge 1 commit into
construct:masterfrom
DresdenGman:fix-1038-select-params

Conversation

@DresdenGman

Copy link
Copy Markdown

Fixes #1038.

When building, Select._build called sc.build(obj, **context), which flattens the context into build keywords — and build_stream then sets context._params to that flattened dict. Constructs nested inside Select that look up this._params (for example IfThenElse(this._params.ctx == 1, Byte, Short)) therefore saw the wrong parameters when building: silently taking the wrong branch with a lambda condition, or raising SelectError with a this._params condition. Parsing was never affected, because _parse passes the context through unchanged.

Following the approach of trying each subcon in place, as _parse does: build each subcon into a temporary stream with a copy of the current context (Container(context)), so _params and everything else survive intact, and context changes made by a failed attempt cannot leak into the next attempt or back into the caller.

Tests: the existing xfail test for this issue (test_select_issue_1038) now passes and its xfail marker is removed, with added assertions for the ctx=2 branch and for the parse direction. Two further tests cover isolation between failed attempts and visibility of sibling fields built before the Select. Full suite: 474 passed, 13 xfailed, against a baseline of 471 passed, 14 xfailed — no new failures.

Select._build used to call sc.build(obj, **context), which flattened
the context into build keywords and reset _params, breaking
this._params lookups in constructs nested inside Select (issue construct#1038).
Build each subcon into a temporary stream with a copy of the current
context instead, mirroring how _parse tries each subcon in place.
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.

IfThenElse inside Select using context not working as intended

1 participant