feat: add Opaque type and allow planner disengagement - #49
Draft
lu-pl wants to merge 2 commits into
Draft
Conversation
lu-pl
marked this pull request as draft
July 23, 2026 15:13
Owner
Author
|
TODO: Tests, tests, tests. 🤖🧪 |
Owner
Author
|
I cannot currently gauge the effect the Currently the behavior is like so: data = [
{"x": 1, "y": 2, "z": 3},
{"x": 1, "y": 3, "z": 4},
{"x": 2, "y": 4, "z": 5},
]
class Nested(BaseModel):
model_config = ConfigDict(group_by="x")
raw: Annotated[Any, Opaque()]
x: int
y: list[int]
class Model(BaseModel):
model_config = ConfigDict(group_by="x")
raw: Annotated[Any, Opaque()]
x: int
z: int
nested: list[Nested]will produce the following bindings: I think this is correct: Nonetheless, this needs careful thinking and testing. |
Owner
Author
|
The following model data = [{"x": 1, "y": 2}, {"x": 1, "y": 3}, {"x": 3, "y": 4}]
class Model(BaseModel):
model_config = ConfigDict(group_by="y")
x: int
y: Annotated[list[int], Opaque()]currently crashes with Should it? |
Owner
Author
|
The following model data = [{"x": 1, "y": 2}, {"x": 1, "y": 3}, {"x": 3, "y": 4}]
class Model(BaseModel):
model_config = ConfigDict(group_by="x")
x: Annotated[int, Opaque]
y: list[int]currently produces {
"x": 1,
"y": [
2,
3
]
}
{
"x": 3,
"y": [
4
]
}I.e. the planner does not recognize I think so, |
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.
The feature adds an
Opaquetype which allows to annotate/flag a model field as 'opaque' to theplanner and causes the planner to disengage; for
Opaque-annotated fields, the entireprojection of the current context is forwarded as a
pl.Struct. I.e. planner semantics do notapply, recursion and aggregation code paths are NOT triggered.
This e.g. allows a before-validator to act on the raw bindings on the Python level.
Example:
Here, the
Opaqueflag disengages the planner, i.e. aggregation is not triggered for theyfield. Instead,
ywill receive the entire struct projection of the current context; the aboveproduces the following bindings:
Note that
Opaquecan also be used to manually handle arbitrary model unions; GraphTy allows onlydiscriminated union types, because those can be resolved at planning time, i.e. the winning union member
is knowable on the Polars-level and not just on the Pydantic-level.
Closes #6.