Thanks to visit codestin.com
Credit goes to github.com

Skip to content

findByID() returns incorrect results compared to equivalent find() #14589

@damnsamn

Description

@damnsamn

Describe the Bug

When using querying with draft: true and a select, the findByID operation will return the most recent draft version even if there is a more recent published version.

Eg:

  1. Create a draft document
  2. Publish the document with changes
  3. Compare equivalent queries for that document, using both find() and findByID() with draft: true and a select for the changed fields
  4. The results will differ

Link to the code that reproduces this issue

https://github.com/damnsamn/blank-payload-project/tree/issue/findbyid-mismatch-find

Reproduction Steps

Run pnpm test, and see that the tests fail. You can resolve this by commenting out the commonQueryOptions.select property in tests/int/api.int.spec.ts

Which area(s) are affected? (Select all that apply)

area: core, db: mongodb

Environment Info

Binaries:
  Node: 23.11.0
  npm: 10.9.2
  Yarn: 1.22.22
  pnpm: 10.17.1
Relevant Packages:
  payload: 3.63.0
  next: 15.4.7
  @payloadcms/db-mongodb: 3.63.0
  @payloadcms/graphql: 3.63.0
  @payloadcms/next/utilities: 3.63.0
  @payloadcms/richtext-lexical: 3.63.0
  @payloadcms/translations: 3.63.0
  @payloadcms/ui/shared: 3.63.0
  react: 19.1.0
  react-dom: 19.1.0
Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.0.0: Mon Aug 12 20:52:31 PDT 2024; root:xnu-11215.1.10~2/RELEASE_ARM64_T6030
  Available memory (MB): 18432
  Available CPU cores: 12

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions