Tuples in unions does not get validated since v3.9.1
See original GitHub issueFollowing schema
const eventsSchema = z.union([
z.object({
eventName: z.literal('foo'),
eventPayload: z.tuple([z.number().nonnegative(), z.number().nonnegative()])
}).strict(),
z.object({
eventName: z.literal('bar'),
eventPayload: z.string().email()
}).strict()
]);
failed before v3.9.1
with following data
const data = {
"eventName": "foo",
"eventPayload": [0, -60]
};
const parseResult = eventsSchema.safeParse(data);
// parseResult.success === true
but since v3.9.1
zod
does not validate the -60
value anymore as .nonnegative()
. Parsing is always successful whereas before v3.9.1
it failed (which is the expected behaviour)
Issue Analytics
- State:
- Created 2 years ago
- Reactions:5
- Comments:9 (3 by maintainers)
Top Results From Across the Web
Type manipulations: union to tuple · Issue #13298 - GitHub
A suggestion to create a runtime array of union members was deemed out of scope because it would not leave the type system...
Read more >5. Data Structures — Python 3.11.1 documentation
Tuples can be used as keys if they contain only strings, numbers, or tuples; if a tuple contains any mutable object either directly...
Read more >Ecto.Changeset — Ecto v3.9.4 - HexDocs
If the changes are valid, all changes are applied to the changeset data. If the changes are invalid, no changes are applied, and...
Read more >Schema Validation - python-jsonschema - Read the Docs
validate () will first verify that the provided schema is itself valid, since not doing so can lead to less obvious error messages...
Read more >Fields - ODMantic
Since by default MongoDB will create a field _id containing an ObjectId primary ... from typing import Union from odmantic import Model class...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Should be fixed in 3.9.2+
Oops looks like I failed to fully roll back the changes that caused this error. I’ve confirmed that all the above cases are working in Zod v3.9.8+.