Skip to content

Conversation

@AdamGlustein
Copy link
Collaborator

@AdamGlustein AdamGlustein commented Oct 10, 2025

Cleanup and a few fixes to #574, thanks @sim15 for the contribution!

Simon Beyzerov and others added 4 commits September 16, 2025 12:03
Signed-off-by: Simon Beyzerov <simon.beyzerov@point72.com>
Signed-off-by: Adam Glustein <adam.glustein@point72.com>
…ance bug

Signed-off-by: Adam Glustein <adam.glustein@point72.com>
@timkpaine timkpaine added the type: enhancement Issues and PRs related to improvements to existing features label Oct 10, 2025
Signed-off-by: Adam Glustein <adam.glustein@point72.com>
@ptomecek
Copy link
Collaborator

ptomecek commented Oct 27, 2025

Previously, when all fields on structs were optional, we hard-coded these two flags for pydantic validation

Can we only apply this logic when allow_unset=True?
I think that when allow_unset is False, pydantic should infer it correctly based on the declared type and the default value, though we should add a unit test.

@AdamGlustein
Copy link
Collaborator Author

Previously, when all fields on structs were optional, we hard-coded these two flags for pydantic validation

Can we only apply this logic when allow_unset=True? I think that when allow_unset is False, pydantic should infer it correctly based on the declared type and the default value, though we should add a unit test.

I tested out this approach and it doesn't validate correctly in the case of a required field with a default value.

class MyStrictStruct(csp.Struct, allow_unset=False):
            req_default_str: str = "default"
E       pydantic_core._pydantic_core.SchemaError: Error building "list" validator:
E         SchemaError: Error building "function-wrap" validator:
E         SchemaError: Error building "typed-dict" validator:
E         SchemaError: Field 'req_default_str': a required field cannot have a default value

@AdamGlustein AdamGlustein requested a review from ptomecek November 3, 2025 20:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: enhancement Issues and PRs related to improvements to existing features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants