Skip to content
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

Local API - findByID works in beta.107 but is broken in beta.108 #8840

Closed
martynasj opened this issue Oct 23, 2024 · 5 comments
Closed

Local API - findByID works in beta.107 but is broken in beta.108 #8840

martynasj opened this issue Oct 23, 2024 · 5 comments

Comments

@martynasj
Copy link

Describe the Bug

I believe that beta.108 broke the payload.findByID api in some way.
This is not an issue in beta.107

*However I was not able to reproduce this issue with the forked payload repo, where I checked out from a beta.108 tag.

Link to the code that reproduces this issue

https://github.com/martynasj/payload/blob/bug/test/_community/int.spec.ts#L51

Reproduction Steps

test('findByID api', async () => {
  const location = await payload.create({
    collection: 'locations',
    data: {
      name: 'New York',
    },
  })

  const allLocations = await payload.find({ collection: 'locations' })
  console.log(allLocations.docs)
  // finds array of these:
  // [
  //   {
  //     id: "671904875c999c26f3964f4a",
  //     name: "New York",
  //     createdAt: "2024-10-23T14:13:27.877Z",
  //     updatedAt: "2024-10-23T14:13:27.877Z",
  //   }
  // ]

  let singleLocation = await payload.db.collections['locations'].findById(location.id)
  console.log(singleLocation)
  // returns object like this:
  // {
  //   coordinates: {},
  //   _id: new ObjectId("671904875c999c26f3964f4a"),
  //   name: "Vilnius International Airport",
  //   createdAt: 2024-10-23T14:13:27.877Z,
  //   updatedAt: 2024-10-23T14:13:27.877Z,
  //   __v: 0,
  // }

  // throws NotFound error
  const singleLoc = await payload.findByID({ collection: 'locations', id: location.id })
})

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

db-mongodb, area: core

Environment Info

Binaries:
Node: 20.17.0
npm: 10.8.2
Yarn: N/A
pnpm: 9.11.0
Relevant Packages:
payload: 3.0.0-beta.108
next: 15.0.0-canary.173
@payloadcms/db-mongodb: 3.0.0-beta.108
@payloadcms/email-nodemailer: 3.0.0-beta.108
@payloadcms/graphql: 3.0.0-beta.108
@payloadcms/next/utilities: 3.0.0-beta.108
@payloadcms/plugin-cloud: 3.0.0-beta.108
@payloadcms/richtext-lexical: 3.0.0-beta.108
@payloadcms/translations: 3.0.0-beta.108
@payloadcms/ui/shared: 3.0.0-beta.108
react: 19.0.0-rc-2d16326d-20240930
react-dom: 19.0.0-rc-2d16326d-20240930

@martynasj martynasj added status: needs-triage Possible bug which hasn't been reproduced yet v3 labels Oct 23, 2024
@paulpopus paulpopus added the status: cant-reproduce If an issue cannot be reproduced label Oct 24, 2024
@github-actions github-actions bot removed the status: needs-triage Possible bug which hasn't been reproduced yet label Oct 24, 2024
@paulpopus
Copy link
Contributor

I tested the provided test in the latest beta and it passes successfully.

In your own project where you're seeing this can you test on the latest beta please? Or at least like beta.116

If it still happens, can you then test it with a fresh database please?

@martynasj
Copy link
Author

@paulpopus thanks for the response! This too seems really weird to me. I replicated the exact same config in the forked payload repo as I'm running and indeed it does work there as opposed in my own repo. Then I noticed that the only difference is the test runner. I'm running my tests with bun test.

So, in the forked repo:

  • running a test with pnpm test:int does PASS
  • running a test with bun test does FAIL

It does fail with this error:

....payload/packages/payload/src/collections/operations/findByID.ts:101:15

 97 |     let result: DataFromCollectionSlug<TSlug> = await req.payload.db.findOne(findOneArgs)
 98 | 
 99 |     if (!result) {
100 |       if (!disableErrors) {
101 |         throw new NotFound(req.t)

I tried to back trace the version of payload when the bun test command started failing and I found that it is beta.108

I do understand that bun is not something that you support, but maybe if you had any idea what was introduced in beta.108 that might've broken the findByID operation in bun environment?

@enricobuehler
Copy link

Having the same problem on beta.118, also using bun. Find function works fine.

@paulpopus
Copy link
Contributor

Sorry guys but Bun is not officially supported right now, at best using it as a package manager is still experimental.

@github-actions github-actions bot removed the status: cant-reproduce If an issue cannot be reproduced label Oct 24, 2024
Copy link
Contributor

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

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants