-
-
Notifications
You must be signed in to change notification settings - Fork 308
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extra template data conflicts with msgspec
discriminated union support
#2211
Comments
I tried an experiment with omitting the class ChatMessagePartFileData(Struct, tag_field="type", tag=None):
type: Literal["file"]
name: str
identifier: str
sizeBytes: float
fileType: FileType |
I've started work on a test case PR that adds additional tests for the extra data handling, including adding an unrelated type (not involved in the union) to the discriminator literals test case for JSON schema. That confirmed there's a genuine problem with that interaction, at least in the jsonschema-to-msgspec case (the openapi-to-msgspec test cases don't cover discriminators). The |
Well, that was a journey. Turns out my initial instinct was almost right. Inadvertent data sharing does happen in the base model constructor, but it's specifically in the The reason it fails is because the values in the |
msgspec
discriminated union support with JSON Schemamsgspec
discriminated union support and extra template data
msgspec
discriminated union support and extra template datamsgspec
discriminated union support
With the patched version from #2215 clearing out the incorrect state sharing errors, I worked out that the other misbehaviours I encountered were due to missing property definition fields in my input schema:
I have retitled this issue accordingly (it now just covers the state sharing bug). |
I am attempting to use the
msgspec
support for the OpenAPIdiscriminator
fields in JSON Schema (as added in da7d054)I've been reverse engineering the expected usage from the test suite, but have hit a point where the behaviour is so strange it feels like a bug:
discriminator
set, every Struct subclass in the generated file hastag_field="type:
andtag=None
(even the ones that have nothing to do with the updated union fields)tag=None
set, and theirtype
field is justLiteral["value"]
rather than the expected class-var-with-default-value that the test suite says I should be gettingI did notice the test suite used
type_
instead oftype
as its discriminator, so I attempted to set{"type": "type_"}
as the alias map, but that didn't make any difference to the output. I can't change the field name in the schema itself, as that's defined by the API I'm writing a client for, not by my client code.I also couldn't find anything in the main documentation indicating that
type
was problematic as a field name.The
generate
call looks like this (kw_only
is set via the extra template data because setting thekeyword_only=True
call option didn't have any effect):And a snippet of the
"definitions"
entry in the input schema:The text was updated successfully, but these errors were encountered: