Skip to content

db-postgres: Pagination shows incorrect totalDocs after deletion using local API with user set #4581

Closed

Description

@joas8211

Link to reproduction

https://github.com/joas8211/payloadcms/tree/repro/postgres-delete-pagination-result

Describe the Bug

When using PostgreSQL as database, deleting the only document from a collection using local API causes the immediately following find call return an incorrect totalDocs count (1 instead of 0). The problem is illustrated by a code snippet below:

await payload.delete({
  collection: 'posts',
  id: post.id,
  user, // <-- Setting user probably creates a transaction
})
const result = await payload.find({
  collection: 'posts',
})
console.log(result)
/*
sometimes:
{
  docs: [],
  hasNextPage: false,
  hasPrevPage: false,
  limit: 10,
  nextPage: null,
  page: 1,
  pagingCounter: 1,
  prevPage: null,
  totalDocs: 1,
  totalPages: 1
}

and sometimes:
{
  docs: [
    {
      id: 1,
      updatedAt: '2023-12-21T11:27:56.354Z',
      createdAt: '2023-12-21T11:27:56.354Z'
    }
  ],
  hasNextPage: false,
  hasPrevPage: false,
  limit: 10,
  nextPage: null,
  page: 1,
  pagingCounter: 1,
  prevPage: null,
  totalDocs: 1,
  totalPages: 1
}
*/

To Reproduce

  1. Clone the reproduction branch:
    git clone [email protected]:joas8211/payloadcms.git --branch repro/postgres-delete-pagination-result
    
  2. Setup development environment for PostgreSQL.
  3. Run test in _community folder using PostgreSQL as database:
    PAYLOAD_DATABASE=postgres pnpm test:int test/_community/int.spec.ts 
    

Payload Version

2.5.0

Adapters and Plugins

db-postgres: 0.2.2

Activity

  1. added
    status: needs-triage
    on Dec 21, 2023
  2. added
    db: postgres
    on Dec 21, 2023
  3. joas8211 commented on Dec 21, 2023

    @joas8211
    ContributorAuthor

    Updated the example in the description, I originally copy-pasted the output from test using mongoose, which was correct output to pass the test, not the right one for this bug. Now there's example outputs while using Postgres adapter. It's noteworthy that the output seems to variate a bit. Sometimes the document is still in the result, sometimes not but totalDocs is still 1.

  4. joas8211 commented on Dec 21, 2023

    @joas8211
    ContributorAuthor

    I got it fixed, so no need to work on this. I'll open a PR.

  5. github-actions commented on Sep 7, 2024

    @github-actions
    Contributor

    This issue has been automatically locked.
    Please open a new issue if this issue persists with any additional detail.

  6. locked as resolved and limited conversation to collaborators on Sep 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

db: postgresstatus: needs-triage

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions