Skip to content

flattenWhere failing for localAPI calls when no 'where' field present #12294

Open
@wrobson-lllow

Description

@wrobson-lllow

Link to reproduction

No response

Describe the Bug

Works as expected

  const servers = await payload.find({
      collection: "collection-slug",
      depth: 0,
      pagination: false,
      where: {}
    });

Throws error:

  const servers = await payload.find({
      collection: "servers",
      depth: 0,
      pagination: false,
    });

Error: TypeError: Cannot convert undefined or null to object
at Function.entries ()
at flattenWhere

To Reproduce

use localAPI without a where field

Issue comes from:

https://github.com/payloadcms/payload/blob/v2.32.2/packages/payload/src/database/queryValidation/validateQueryPaths.ts

Fix:

Replace line 34 with:

 Object.entries(query ?? {}).reduce((flattenedConstraints, [key, val]) => {

Payload Version

2.32.2

Adapters and Plugins

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions