Skip to content

Conversation

piotracalski
Copy link
Contributor

Problem

Model.validate() hangs indefinitely when all specified validation paths fail type casting. The Promise never resolves or rejects, causing timeouts.

Root cause

  1. castObject() throws a ValidationError and removes failed paths from the validation queue
  2. The main validation loop becomes empty (remaining = 0)
  3. _checkDone() is never called because the loop doesn't execute
  4. The Promise hangs indefinitely

Solution

Refactored the Promise handling logic to properly handle the case when all validation paths are removed due to casting errors. The key changes:
Early settlement check: Added if (remaining === 0) { return settle(); } immediately after creating the Promise to handle the case where no paths need validation
Extracted settlement logic: Created a settle() helper function to centralize Promise resolution/rejection logic

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a critical bug where Model.validate() would hang indefinitely when all specified validation paths fail type casting. The issue occurred because the validation loop would become empty after casting failures, but the Promise would never be resolved or rejected.

  • Refactored Promise handling logic to detect when no validation paths remain
  • Added early settlement check to prevent hanging when all paths are removed
  • Extracted settlement logic into a reusable helper function

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
lib/model.js Fixed Promise hanging issue by adding early settlement check and extracting settlement logic
test/model.validate.test.js Added test case to verify the fix handles casting failures correctly

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@vkarpov15 vkarpov15 added this to the 8.17.2 milestone Aug 12, 2025
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Collaborator

@vkarpov15 vkarpov15 left a comment

Choose a reason for hiding this comment

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

Thanks 👍

@vkarpov15 vkarpov15 merged commit 444d941 into Automattic:master Aug 13, 2025
36 of 37 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