Repository navigation
fix(zod): exclude computed/discriminator fields from update schemas #2417
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
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e23e349
fix(zod): exclude computed/discriminator fields from update schemas
claude[bot] a62d4c3
fix: remove redundant happy path tests from zod factory test
claude[bot] f54ce71
fix(test): remove incorrect data wrapper from update schema tests
claude[bot] aa0b70f
fix(test): correct discriminator field test structure and remove data…
claude[bot] 4063725
feat(zod): add type-level validation tests for computed and discrimin…
claude[bot] 927791d
fix(test): remove problematic type-level tests that cause TypeScript …
claude[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
# First, let's look at the test file around the specified lines wc -l packages/zod/test/factory.test.tsRepository: zenstackhq/zenstack
Length of output: 100
🏁 Script executed:
Repository: zenstackhq/zenstack
Length of output: 4113
🏁 Script executed:
Repository: zenstackhq/zenstack
Length of output: 1347
🏁 Script executed:
Repository: zenstackhq/zenstack
Length of output: 124
🏁 Script executed:
Repository: zenstackhq/zenstack
Length of output: 7865
🏁 Script executed:
Repository: zenstackhq/zenstack
Length of output: 338
🏁 Script executed:
Repository: zenstackhq/zenstack
Length of output: 4942
🏁 Script executed:
Repository: zenstackhq/zenstack
Length of output: 2510
🏁 Script executed:
Repository: zenstackhq/zenstack
Length of output: 3874
🏁 Script executed:
Repository: zenstackhq/zenstack
Length of output: 620
🏁 Script executed:
Repository: zenstackhq/zenstack
Length of output: 45
🏁 Script executed:
Repository: zenstackhq/zenstack
Length of output: 45
🏁 Script executed:
Repository: zenstackhq/zenstack
Length of output: 45
🏁 Script executed:
Repository: zenstackhq/zenstack
Length of output: 8600
🏁 Script executed:
Repository: zenstackhq/zenstack
Length of output: 5707
🏁 Script executed:
Repository: zenstackhq/zenstack
Length of output: 45
🏁 Script executed:
Repository: zenstackhq/zenstack
Length of output: 45
🏁 Script executed:
Repository: zenstackhq/zenstack
Length of output: 1101
🏁 Script executed:
Repository: zenstackhq/zenstack
Length of output: 45
🏁 Script executed:
Repository: zenstackhq/zenstack
Length of output: 45
🏁 Script executed:
Repository: zenstackhq/zenstack
Length of output: 937
🏁 Script executed:
Repository: zenstackhq/zenstack
Length of output: 45
🏁 Script executed:
Repository: zenstackhq/zenstack
Length of output: 45
🏁 Script executed:
Repository: zenstackhq/zenstack
Length of output: 3169
🏁 Script executed:
Repository: zenstackhq/zenstack
Length of output: 45
🏁 Script executed:
Repository: zenstackhq/zenstack
Length of output: 250
🏁 Script executed:
Repository: zenstackhq/zenstack
Length of output: 94
🏁 Script executed:
Repository: zenstackhq/zenstack
Length of output: 45
🏁 Script executed:
Repository: zenstackhq/zenstack
Length of output: 491
🏁 Script executed:
Repository: zenstackhq/zenstack
Length of output: 859
🏁 Script executed:
Repository: zenstackhq/zenstack
Length of output: 45
🏁 Script executed:
Repository: zenstackhq/zenstack
Length of output: 45
🏁 Script executed:
Repository: zenstackhq/zenstack
Length of output: 2030
🏁 Script executed:
Repository: zenstackhq/zenstack
Length of output: 990
🏁 Script executed:
Repository: zenstackhq/zenstack
Length of output: 3273
🏁 Script executed:
Repository: zenstackhq/zenstack
Length of output: 45
🏁 Script executed:
Repository: zenstackhq/zenstack
Length of output: 45
🏁 Script executed:
Repository: zenstackhq/zenstack
Length of output: 45
🏁 Script executed:
Repository: zenstackhq/zenstack
Length of output: 1160
🏁 Script executed:
Repository: zenstackhq/zenstack
Length of output: 45
🏁 Script executed:
Repository: zenstackhq/zenstack
Length of output: 1000
🏁 Script executed:
Repository: zenstackhq/zenstack
Length of output: 4646
🏁 Script executed:
Repository: zenstackhq/zenstack
Length of output: 6827
🏁 Script executed:
Repository: zenstackhq/zenstack
Length of output: 45
🏁 Script executed:
Repository: zenstackhq/zenstack
Length of output: 45
Exclude computed and discriminator fields from create/update schemas, and fix error assertions to check
issue.keysinstead ofissue.path.The factory code doesn't filter out
computedandisDiscriminatorfields when building create and update schemas—only relations are excluded. This means computed fields likepostCountand discriminator fields likeassetTypeare included in the schemas when they shouldn't be.Additionally, when these fields are passed during validation, Zod reports them as unrecognized keys via
code === 'unrecognized_keys'withkeys: string[], not throughissue.path. The test assertions checkingissue.path[0]will fail because unrecognized keys have empty paths.Fix both issues:
makeModelCreateSchemaandmakeModelUpdateSchemaissue.code === 'unrecognized_keys' && issue.keys.includes(fieldName)instead of checkingissue.pathProposed fixes
In packages/zod/src/factory.ts, update the loops to exclude computed and discriminator fields:
for (const [fieldName, fieldDef] of Object.entries(modelDef.fields)) { if (fieldDef.relation) { continue; } + if (fieldDef.computed || fieldDef.isDiscriminator) { + continue; + }In packages/zod/test/factory.test.ts, update error assertions:
🤖 Prompt for AI Agents