Skip to content

fix(model): stop Model.validate() crashing on missing nested objects - #16600

Merged
vkarpov15 merged 1 commit into
Automattic:masterfrom
NotAFlightRisk:fix/model-validate-nested-crash
Oct 18, 2026
Merged

vkarpov15 merged 1 commit into
Automattic:masterfrom
NotAFlightRisk:fix/model-validate-nested-crash

Conversation

@NotAFlightRisk

Copy link
Copy Markdown
Contributor

Summary

Give a schema a path three levels deep, like profile.address.city, and Model.validate({ name: 'x' }) rejects with TypeError: Cannot read properties of undefined (reading 'address') instead of validating. Model['~standard'].validate() goes through the same code, so it hands that TypeError back as the only issue for input thats perfectly valid.

The loop that throws walks down to each path's parent and never reads what it finds (castObject() does the writing back now), so I've just taken it out.

Examples

Added a test with no profile at all. On master it gets the TypeError, with this it gets the required error for profile.address.city.

@vkarpov15 vkarpov15 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good find, thanks 👍

@vkarpov15 vkarpov15 added this to the 9.11.3 milestone Oct 18, 2026
@vkarpov15
vkarpov15 merged commit ac05ac2 into Automattic:master Oct 18, 2026
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants