Skip to content

fix(sdk): pass trash to request#16092

Merged
PatrikKozak merged 4 commits intopayloadcms:mainfrom
nathanbowang:fix/sdk-trash-parameter
Mar 30, 2026
Merged

fix(sdk): pass trash to request#16092
PatrikKozak merged 4 commits intopayloadcms:mainfrom
nathanbowang:fix/sdk-trash-parameter

Conversation

@nathanbowang
Copy link
Copy Markdown
Contributor

@nathanbowang nathanbowang commented Mar 29, 2026

What?

The REST SDK documents a trash option on find, findVersions, and findVersionByID, but that flag was never added to the request URL. The Local API and REST handlers already support trash via query params (parseParams / collection endpoints).

Why?

Users enabling soft delete (trash) need trash: true on list/version queries to include trashed documents (or to query the trash view). Passing trash from the SDK had no effect because buildSearchParams omitted it, so the REST API always behaved as if trash was unset.

How?

  • Extended OperationArgs in packages/sdk/src/utilities/buildSearchParams.ts with optional trash?: boolean.
  • When trash is a boolean, serialize it to the query string (same pattern as draft).
  • Added an integration test in test/sdk/int.spec.ts that uses a stub fetch and asserts the requested URL contains trash=true for find, findVersions, and findVersionByID.

Before: sdk.find({ collection: 'posts', trash: true }) → request had no trash query param.

After: same call → ...?trash=true&... (alongside other params).

Fixes #


@nathanbowang nathanbowang changed the title Pass trash to request fix: pass trash to request Mar 29, 2026
Copy link
Copy Markdown
Member

@r1tsuu r1tsuu left a comment

Choose a reason for hiding this comment

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

Thanks! Add an integration test for this in test/sdk/int.spec.ts please

@r1tsuu r1tsuu changed the title fix: pass trash to request fix(sdk): pass trash to request Mar 29, 2026
@nathanbowang
Copy link
Copy Markdown
Contributor Author

Thanks! Add an integration test for this in test/sdk/int.spec.ts please

Done.

@nathanbowang nathanbowang requested a review from r1tsuu March 29, 2026 10:52
@PatrikKozak PatrikKozak self-assigned this Mar 30, 2026
@PatrikKozak PatrikKozak self-requested a review March 30, 2026 13:14
@PatrikKozak PatrikKozak merged commit e0b3e81 into payloadcms:main Mar 30, 2026
152 checks passed
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 1, 2026

🚀 This is included in version v3.81.0

milamer pushed a commit to milamer/payload that referenced this pull request Apr 20, 2026
### What?

The REST SDK documents a `trash` option on `find`, `findVersions`, and
`findVersionByID`, but that flag was never added to the request URL. The
Local API and REST handlers already support `trash` via query params
(`parseParams` / collection endpoints).

### Why?

Users enabling [soft delete
(trash)](https://payloadcms.com/docs/trash/overview) need `trash: true`
on list/version queries to include trashed documents (or to query the
trash view). Passing `trash` from the SDK had no effect because
`buildSearchParams` omitted it, so the REST API always behaved as if
`trash` was unset.

### How?

- Extended `OperationArgs` in
`packages/sdk/src/utilities/buildSearchParams.ts` with optional `trash?:
boolean`.
- When `trash` is a boolean, serialize it to the query string (same
pattern as `draft`).
- Added an integration test in `test/sdk/int.spec.ts` that uses a stub
`fetch` and asserts the requested URL contains `trash=true` for `find`,
`findVersions`, and `findVersionByID`.

**Before:** `sdk.find({ collection: 'posts', trash: true })` → request
had no `trash` query param.

**After:** same call → `...?trash=true&...` (alongside other params).

Fixes #

---
- To see the specific tasks where the Asana app for GitHub is being
used, see below:
  - https://app.asana.com/0/0/1213864434332542

---------

Co-authored-by: Sasha Rakhmatulin <sasha@ritsuko.dev>
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.

3 participants