Skip to content

fix(query): handle casting array filter paths underneath array filter paths with embedded discriminators #15388

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

Merged
merged 3 commits into from
May 5, 2025

Conversation

vkarpov15
Copy link
Collaborator

Fix #15386

Summary

The issue in #15386 is that events.$[event].products.$[product].price updates don't quite work if products is a path on an embedded discriminator where the discriminator key is set in the event array filter.

To get that to work, we needed to first fix castArrayFilters() to handle this pattern when casting array filters, and then improve how we handle casting the update in castUpdate() (getEmbeddedDiscriminatorPath() changes).

Examples

@vkarpov15 vkarpov15 added this to the 8.14.2 milestone Apr 30, 2025
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 an issue with casting array filter paths that reference embedded discriminators, as described in #15386. Key changes include:

  • Adding and propagating a discriminator value map in castArrayFilters and getPath.
  • Updating getEmbeddedDiscriminatorPath to correctly handle starting indices when processing embedded discriminator paths.
  • Adding tests for the new pattern in update.castArrayFilters.test.js.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
test/helpers/update.castArrayFilters.test.js Added a new test validating proper casting of array filter paths with embedded discriminators.
lib/helpers/update/castArrayFilters.js Modified to build a discriminator value map and pass it to getPath for embedded discriminator casting.
lib/helpers/schema/getPath.js Updated the function signature to accept a discriminator value map and use it when traversing the schema.
lib/helpers/query/getEmbeddedDiscriminatorPath.js Adjusted the path splitting logic by introducing a startIndex to handle multiple embedded discriminators.
Comments suppressed due to low confidence (1)

lib/helpers/query/getEmbeddedDiscriminatorPath.js:32

  • [nitpick] Consider renaming 'startIndex' to something like 'discriminatorStartIndex' to more clearly indicate its purpose.
const originalSubpath = parts.slice(startIndex, i + 1).join('.');

Copy link
Collaborator

@hasezoey hasezoey left a comment

Choose a reason for hiding this comment

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

LGTM, some minor nitpicks.

@vkarpov15 vkarpov15 merged commit 6580d73 into master May 5, 2025
30 of 31 checks passed
@vkarpov15 vkarpov15 deleted the vkarpov15/gh-15386 branch May 5, 2025 19:36
mergify bot added a commit to reisene/HulajDusza-serwis that referenced this pull request Jun 9, 2025
![snyk-io[bot]](https://badgen.net/badge/icon/snyk-io%5Bbot%5D/green?label=)
![Contributor](https://badgen.net/badge/icon/Contributor/000000?label=)
[<img width="16" alt="Powered by Pull Request Badge"
src="https://user-images.githubusercontent.com/1393946/111216524-d2bb8e00-85d4-11eb-821b-ed4c00989c02.png">](https://pullrequestbadge.com/?utm_medium=github&utm_source=reisene&utm_campaign=badge_info)<!--
PR-BADGE: PLEASE DO NOT REMOVE THIS COMMENT -->


![snyk-top-banner](https://res.cloudinary.com/snyk/image/upload/r-d/scm-platform/snyk-pull-requests/pr-banner-default.svg)


<h3>Snyk has created this PR to upgrade mongoose from 8.14.2 to
8.14.3.</h3>

:information_source: Keep your dependencies up-to-date. This makes it
easier to fix existing vulnerabilities and to more quickly identify and
fix newly disclosed vulnerabilities when they affect your project.

<hr/>


- The recommended version is **1 version** ahead of your current
version.

- The recommended version was released **23 days ago**.



<details>
<summary><b>Release notes</b></summary>
<br/>
  <details>
    <summary>Package name: <b>mongoose</b></summary>
    <ul>
      <li>
<b>8.14.3</b> - <a
href="https://redirect.github.com/Automattic/mongoose/releases/tag/8.14.3">2025-05-13</a></br><h1>8.14.3
/ 2025-05-13</h1>
<ul>
<li>types(schema): allow post('init') <a class="issue-link
js-issue-link" data-error-text="Failed to load title"
data-id="3049961081" data-permission-text="Title is private"
data-url="Automattic/mongoose#15413"
data-hovercard-type="pull_request"
data-hovercard-url="/Automattic/mongoose/pull/15413/hovercard"
href="https://redirect.github.com/Automattic/mongoose/pull/15413">#15413</a>
<a class="issue-link js-issue-link" data-error-text="Failed to load
title" data-id="3049127827" data-permission-text="Title is private"
data-url="Automattic/mongoose#15412"
data-hovercard-type="issue"
data-hovercard-url="/Automattic/mongoose/issues/15412/hovercard"
href="https://redirect.github.com/Automattic/mongoose/issues/15412">#15412</a>
<a class="issue-link js-issue-link" data-error-text="Failed to load
title" data-id="2956580603" data-permission-text="Title is private"
data-url="Automattic/mongoose#15333"
data-hovercard-type="pull_request"
data-hovercard-url="/Automattic/mongoose/pull/15333/hovercard"
href="https://redirect.github.com/Automattic/mongoose/pull/15333">#15333</a></li>
<li>types: fix signature of DocumentArray.id <a class="issue-link
js-issue-link" data-error-text="Failed to load title"
data-id="3050874869" data-permission-text="Title is private"
data-url="Automattic/mongoose#15414"
data-hovercard-type="pull_request"
data-hovercard-url="/Automattic/mongoose/pull/15414/hovercard"
href="https://redirect.github.com/Automattic/mongoose/pull/15414">#15414</a>
<a href="https://redirect.github.com/Sainan">Sainan</a></li>
<li>docs: fix typo - change 'prodecure' to 'procedure' <a
class="issue-link js-issue-link" data-error-text="Failed to load title"
data-id="3059701782" data-permission-text="Title is private"
data-url="Automattic/mongoose#15419"
data-hovercard-type="pull_request"
data-hovercard-url="/Automattic/mongoose/pull/15419/hovercard"
href="https://redirect.github.com/Automattic/mongoose/pull/15419">#15419</a>
<a href="https://redirect.github.com/0xEbrahim">0xEbrahim</a></li>
</ul>
      </li>
      <li>
<b>8.14.2</b> - <a
href="https://redirect.github.com/Automattic/mongoose/releases/tag/8.14.2">2025-05-08</a></br><h1>8.14.2
/ 2025-05-08</h1>
<ul>
<li>fix(query): handle casting array filter paths underneath array
filter paths with embedded discriminators <a class="issue-link
js-issue-link" data-error-text="Failed to load title"
data-id="3032109299" data-permission-text="Title is private"
data-url="Automattic/mongoose#15388"
data-hovercard-type="pull_request"
data-hovercard-url="/Automattic/mongoose/pull/15388/hovercard"
href="https://redirect.github.com/Automattic/mongoose/pull/15388">#15388</a>
<a class="issue-link js-issue-link" data-error-text="Failed to load
title" data-id="3030764860" data-permission-text="Title is private"
data-url="Automattic/mongoose#15386"
data-hovercard-type="issue"
data-hovercard-url="/Automattic/mongoose/issues/15386/hovercard"
href="https://redirect.github.com/Automattic/mongoose/issues/15386">#15386</a></li>
<li>docs(typescript): correct schema and model generic params in TS
virtuals docs <a class="issue-link js-issue-link"
data-error-text="Failed to load title" data-id="3034576277"
data-permission-text="Title is private"
data-url="Automattic/mongoose#15391"
data-hovercard-type="pull_request"
data-hovercard-url="/Automattic/mongoose/pull/15391/hovercard"
href="https://redirect.github.com/Automattic/mongoose/pull/15391">#15391</a></li>
<li>docs+types(schema): add alternative optimisticConcurrency syntaxes
to docs + types <a class="issue-link js-issue-link"
data-error-text="Failed to load title" data-id="3040923211"
data-permission-text="Title is private"
data-url="Automattic/mongoose#15405"
data-hovercard-type="pull_request"
data-hovercard-url="/Automattic/mongoose/pull/15405/hovercard"
href="https://redirect.github.com/Automattic/mongoose/pull/15405">#15405</a>
<a class="issue-link js-issue-link" data-error-text="Failed to load
title" data-id="977085280" data-permission-text="Title is private"
data-url="Automattic/mongoose#10591"
data-hovercard-type="issue"
data-hovercard-url="/Automattic/mongoose/issues/10591/hovercard"
href="https://redirect.github.com/Automattic/mongoose/issues/10591">#10591</a></li>
<li>chore: add Node 24 to CI matrix <a class="issue-link js-issue-link"
data-error-text="Failed to load title" data-id="3044942226"
data-permission-text="Title is private"
data-url="Automattic/mongoose#15408"
data-hovercard-type="pull_request"
data-hovercard-url="/Automattic/mongoose/pull/15408/hovercard"
href="https://redirect.github.com/Automattic/mongoose/pull/15408">#15408</a>
<a href="https://redirect.github.com/stscoundrel">stscoundrel</a></li>
</ul>
      </li>
    </ul>
from <a
href="https://redirect.github.com/Automattic/mongoose/releases">mongoose
GitHub release notes</a>
  </details>
</details>

---

> [!IMPORTANT]
>
> - Check the changes in this PR to ensure they won't cause issues with
your project.
> - This PR was automatically created by Snyk using the credentials of a
real user.

---

**Note:** _You are seeing this because you or someone else with access
to this repository has authorized Snyk to open upgrade PRs._

**For more information:** <img
src="https://api.segment.io/v1/pixel/track?data=eyJ3cml0ZUtleSI6InJyWmxZcEdHY2RyTHZsb0lYd0dUcVg4WkFRTnNCOUEwIiwiYW5vbnltb3VzSWQiOiI1OTM5YTZhZi1hYTQ4LTQ3MzEtYjE2Ny01Zjk4NmRjY2VkYTgiLCJldmVudCI6IlBSIHZpZXdlZCIsInByb3BlcnRpZXMiOnsicHJJZCI6IjU5MzlhNmFmLWFhNDgtNDczMS1iMTY3LTVmOTg2ZGNjZWRhOCJ9fQ=="
width="0" height="0"/>

> - 🧐 [View latest project
report](https://app.snyk.io/org/reisene/project/55e114f8-489e-4f14-b900-20574b041e59?utm_source&#x3D;github-cloud-app&amp;utm_medium&#x3D;referral&amp;page&#x3D;upgrade-pr)
> - 📜 [Customise PR
templates](https://docs.snyk.io/scan-using-snyk/pull-requests/snyk-fix-pull-or-merge-requests/customize-pr-templates?utm_source=&utm_content=fix-pr-template)
> - 🛠 [Adjust upgrade PR
settings](https://app.snyk.io/org/reisene/project/55e114f8-489e-4f14-b900-20574b041e59/settings/integration?utm_source&#x3D;github-cloud-app&amp;utm_medium&#x3D;referral&amp;page&#x3D;upgrade-pr)
> - 🔕 [Ignore this dependency or unsubscribe from future upgrade
PRs](https://app.snyk.io/org/reisene/project/55e114f8-489e-4f14-b900-20574b041e59/settings/integration?pkg&#x3D;mongoose&amp;utm_source&#x3D;github-cloud-app&amp;utm_medium&#x3D;referral&amp;page&#x3D;upgrade-pr#auto-dep-upgrades)

[//]: #
'snyk:metadata:{"customTemplate":{"variablesUsed":[],"fieldsUsed":[]},"dependencies":[{"name":"mongoose","from":"8.14.2","to":"8.14.3"}],"env":"prod","hasFixes":false,"isBreakingChange":false,"isMajorUpgrade":false,"issuesToFix":[],"prId":"5939a6af-aa48-4731-b167-5f986dcceda8","prPublicId":"5939a6af-aa48-4731-b167-5f986dcceda8","packageManager":"npm","priorityScoreList":[],"projectPublicId":"55e114f8-489e-4f14-b900-20574b041e59","projectUrl":"https://app.snyk.io/org/reisene/project/55e114f8-489e-4f14-b900-20574b041e59?utm_source=github-cloud-app&utm_medium=referral&page=upgrade-pr","prType":"upgrade","templateFieldSources":{"branchName":"default","commitMessage":"default","description":"default","title":"default"},"templateVariants":[],"type":"auto","upgrade":[],"upgradeInfo":{"versionsDiff":1,"publishedDate":"2025-05-13T15:27:19.721Z"},"vulns":[]}'

## Podsumowanie od Sourcery

Prace porządkowe:
- Aktualizacja mongoose z wersji 8.14.2 do 8.14.3 w pliku package.json

<details>
<summary>Original summary in English</summary>

## Summary by Sourcery

Chores:
- Bump mongoose from 8.14.2 to 8.14.3 in package.json

</details>
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.

Arrayfilters does not work with nested array with descriminator
2 participants