payloadcms / payload

Payload is the open-source, fullstack Next.js framework, giving you instant backend superpowers. Get a full TypeScript backend and admin panel instantly. Use Payload as a headless CMS or for building powerful applications.
https://payloadcms.com
MIT License
23.42k stars 1.49k forks source link

Searching for number id: Unhandled Runtime Error (Error: invalid input syntax for type integer: "NaN") #8347

Closed mobeigi closed 14 minutes ago

mobeigi commented 2 days ago

Link to reproduction

No response

Environment Info

Binaries:
  Node: 20.16.0
  npm: N/A
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  payload: 3.0.0-beta.108
  next: 15.0.0-canary.161
  @payloadcms/db-postgres: 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/plugin-nested-docs: 3.0.0-beta.108
  @payloadcms/plugin-seo: 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-e4953922-20240919
  react-dom: 19.0.0-rc-e4953922-20240919
Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 10 Pro
  Available memory (MB): 65459
  Available CPU cores: 24

Done in 1.68s.

Describe the Bug

Actual Behaviour

You have a collection and your default search is for the collection id (which is a number field). If you search for something that is not a number like a string, it throws a runtime error in admin ui.

Unhandled Runtime Error
Error: invalid input syntax for type integer: "NaN"

Expected Behaviour

Even though we are searching for a number, if I enter text the admin UI should not crash and instead silently cast the string to a number (or silently fail otherwise by showing no results).

Temporary workaround

You can change the search term to a string type to avoid this issue:

admin: {
  listSearchableFields: ['displayName', 'email'],
}

Unfortunately, even if you include id in above list of searchable fields, it still will throw the error upon searching for a string.

Reproduction Steps

  1. Create any collection (it should have an id field)
  2. Go to admin UI for collection and input a search query that is not a number
  3. Runtime error is observed

Adapters and Plugins

No response

paulpopus commented 5 hours ago

Reproduced with postgres, sqlite seems to not error out on this one

r1tsuu commented 14 minutes ago

Thanks for the report! Fixed in https://github.com/payloadcms/payload/pull/8369