Skip to content

3.26.0 throws error when change relation in a collection #11583

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

Open
maxkarkowski opened this issue Mar 7, 2025 · 5 comments
Open

3.26.0 throws error when change relation in a collection #11583

maxkarkowski opened this issue Mar 7, 2025 · 5 comments
Labels
stale status: needs-triage Possible bug which hasn't been reproduced yet

Comments

@maxkarkowski
Copy link

maxkarkowski commented Mar 7, 2025

Describe the Bug

Hi i have a collection courses with multiple relations to other collections. After updating to the newest version of payload i get a strange behaviour when trying to add a relation for a single course(seen in video)

This is my Course Collection

message.txt

and this my organizer collection

import type { CollectionConfig } from 'payload'

import { anyone } from '../access/anyone'
import { authenticated } from '../access/authenticated'
import { isValidURL } from '@/utilities/validUrl'

export const Organizers: CollectionConfig = {
  slug: 'organizers',
  labels: {
    singular: {
      en: 'Organizer',
      de: 'Organisator',
    },
    plural: {
      en: 'Organizers',
      de: 'Organisatoren',
    },
  },
  access: {
    create: authenticated,
    delete: authenticated,
    read: anyone,
    update: authenticated,
  },
  admin: {
    useAsTitle: 'title',
  },
  fields: [
    {
      name: 'title',
      type: 'text',
      required: true,
    },
    {
      name: 'mail',
      type: 'email',
      required: true,
    },
    {
      name: 'url',
      type: 'text',
      required: false,
      validate: (value) => {
        if (!value) return true // Allow empty values
        return isValidURL(value) || 'Invalid URL'
      },
    },
    {
      name: 'adress',
      type: 'group',
      fields: [
        { name: 'street', type: 'text' },
        {
          type: 'row',
          fields: [
            { name: 'zip', type: 'text' },
            { name: 'city', type: 'text' },
          ],
        },
      ],
      admin: {
        components: {
          Cell: '/components/Payload/AdressCell',
        },
      },
    },
    { name: 'relatedCourses', type: 'join', collection: 'courses', on: 'organizer' },
  ],
}

if i try to change something it only shows an error.
It happens only if a upgrade to version 3.26.0 or above. in version 3.25.0 it still works.
it says "no title" in the api view there is clearly a title

this is the error message i get when i try to change the field organizer or categories

[11:46:17] ERROR: Invalid hint. undefined
    err: {
      "type": "TypeError",
      "message": "Invalid hint. undefined",
      "stack":
          TypeError: Invalid hint. undefined
              at Query.hint (webpack-internal:///(rsc)/./node_modules/.pnpm/[email protected]/node_modules/mquery/lib/mquery.js:1496:9)
              at Query.setOptions (webpack-internal:///(rsc)/./node_modules/.pnpm/[email protected]_@[email protected]/node_modules/mongoose/lib/query.js:1758:17)
              at Function.countDocuments (webpack-internal:///(rsc)/./node_modules/.pnpm/[email protected]_@[email protected]/node_modules/mongoose/lib/model.js:2149:8)
              at aggregatePaginate (webpack-internal:///(rsc)/./node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected][email protected]_/node_modules/@payloadcms/db-mongodb/dist/utilities/aggregatePaginate.js:48:34)
              at Object.find (webpack-internal:///(rsc)/./node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected][email protected]_/node_modules/@payloadcms/db-mongodb/dist/find.js:113:106)
              at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
              at async findOperation (webpack-internal:///(rsc)/./node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/payload/dist/collections/operations/find.js:122:22)
              at async findHandler (webpack-internal:///(rsc)/./node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/payload/dist/collections/endpoints/find.js:25:20)
              at async handleEndpoints (webpack-internal:///(rsc)/./node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/payload/dist/utilities/handleEndpoints.js:178:26)
              at async handleEndpoints (webpack-internal:///(rsc)/./node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/payload/dist/utilities/handleEndpoints.js:71:26)
              at async eval (webpack-internal:///(rsc)/./node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected][email protected]_exwf4i4p6y5kcle5wsmskys3hq/node_modules/@payloadcms/next/dist/routes/rest/index.js:27:20)
              at async AppRouteRouteModule.do (/Users/max.karkowski/projects/courses/node_modules/.pnpm/[email protected][email protected][email protected][email protected][email protected]/node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:24:33911)
              at async AppRouteRouteModule.handle (/Users/max.karkowski/projects/courses/node_modules/.pnpm/[email protected][email protected][email protected][email protected][email protected]/node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:24:41240)
              at async doRender (/Users/max.karkowski/projects/courses/node_modules/.pnpm/[email protected][email protected][email protected][email protected][email protected]/node_modules/next/dist/server/base-server.js:1517:42)
              at async responseGenerator (/Users/max.karkowski/projects/courses/node_modules/.pnpm/[email protected][email protected][email protected][email protected][email protected]/node_modules/next/dist/server/base-server.js:1906:28)
              at async DevServer.renderToResponseWithComponentsImpl (/Users/max.karkowski/projects/courses/node_modules/.pnpm/[email protected][email protected][email protected][email protected][email protected]/node_modules/next/dist/server/base-server.js:1917:28)
              at async DevServer.renderPageComponent (/Users/max.karkowski/projects/courses/node_modules/.pnpm/[email protected][email protected][email protected][email protected][email protected]/node_modules/next/dist/server/base-server.js:2365:24)
              at async DevServer.renderToResponseImpl (/Users/max.karkowski/projects/courses/node_modules/.pnpm/[email protected][email protected][email protected][email protected][email protected]/node_modules/next/dist/server/base-server.js:2402:32)
              at async DevServer.pipeImpl (/Users/max.karkowski/projects/courses/node_modules/.pnpm/[email protected][email protected][email protected][email protected][email protected]/node_modules/next/dist/server/base-server.js:1009:25)
              at async NextNodeServer.handleCatchallRenderRequest (/Users/max.karkowski/projects/courses/node_modules/.pnpm/[email protected][email protected][email protected][email protected][email protected]/node_modules/next/dist/server/next-server.js:301:17)
              at async DevServer.handleRequestImpl (/Users/max.karkowski/projects/courses/node_modules/.pnpm/[email protected][email protected][email protected][email protected][email protected]/node_modules/next/dist/server/base-server.js:898:17)
              at async /Users/max.karkowski/projects/courses/node_modules/.pnpm/[email protected][email protected][email protected][email protected][email protected]/node_modules/next/dist/server/dev/next-dev-server.js:371:20
              at async Span.traceAsyncFn (/Users/max.karkowski/projects/courses/node_modules/.pnpm/[email protected][email protected][email protected][email protected][email protected]/node_modules/next/dist/trace/trace.js:157:20)
              at async DevServer.handleRequest (/Users/max.karkowski/projects/courses/node_modules/.pnpm/[email protected][email protected][email protected][email protected][email protected]/node_modules/next/dist/server/dev/next-dev-server.js:368:24)
              at async invokeRender (/Users/max.karkowski/projects/courses/node_modules/.pnpm/[email protected][email protected][email protected][email protected][email protected]/node_modules/next/dist/server/lib/router-server.js:234:21)
              at async handleRequest (/Users/max.karkowski/projects/courses/node_modules/.pnpm/[email protected][email protected][email protected][email protected][email protected]/node_modules/next/dist/server/lib/router-server.js:422:24)
              at async requestHandlerImpl (/Users/max.karkowski/projects/courses/node_modules/.pnpm/[email protected][email protected][email protected][email protected][email protected]/node_modules/next/dist/server/lib/router-server.js:446:13)
              at async Server.requestListener (/Users/max.karkowski/projects/courses/node_modules/.pnpm/[email protected][email protected][email protected][email protected][email protected]/node_modules/next/dist/server/lib/start-server.js:158:13)
    }

Link to the code that reproduces this issue

https://github.com/maxkarkowski/courses/blob/main/src/collections/Courses/index.ts

Reproduction Steps

i could not reproduce is in a fresh install of payload, even though i used the same collections. you can try to use my repo(made it public for this issue). just update to version 3.26.0

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

Not sure

Environment Info

Binaries:
  Node: 22.14.0
  npm: 10.9.2
  Yarn: N/A
  pnpm: 9.15.4
Relevant Packages:
  payload: 3.25.0
  next: 15.2.1
  @payloadcms/db-mongodb: 3.25.0
  @payloadcms/db-postgres: 3.25.0
  @payloadcms/email-nodemailer: 3.25.0
  @payloadcms/email-resend: 3.25.0
  @payloadcms/graphql: 3.25.0
  @payloadcms/live-preview: 3.25.0
  @payloadcms/live-preview-react: 3.25.0
  @payloadcms/next/utilities: 3.25.0
  @payloadcms/payload-cloud: 3.25.0
  @payloadcms/plugin-cloud-storage: 3.25.0
  @payloadcms/plugin-form-builder: 3.25.0
  @payloadcms/plugin-nested-docs: 3.25.0
  @payloadcms/plugin-redirects: 3.25.0
  @payloadcms/plugin-search: 3.25.0
  @payloadcms/plugin-seo: 3.25.0
  @payloadcms/richtext-lexical: 3.25.0
  @payloadcms/storage-s3: 3.25.0
  @payloadcms/storage-uploadthing: 3.25.0
  @payloadcms/translations: 3.25.0
  @payloadcms/ui/shared: 3.25.0
  react: 19.0.0
  react-dom: 19.0.0
Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.3.0: Thu Jan  2 20:24:22 PST 2025; root:xnu-11215.81.4~3/RELEASE_ARM64_T6041
  Available memory (MB): 49152
  Available CPU cores: 14
@maxkarkowski maxkarkowski added status: needs-triage Possible bug which hasn't been reproduced yet validate-reproduction Auto-added tag on create to tell bot to check recreation URL, removed after check. labels Mar 7, 2025
@github-actions github-actions bot removed the validate-reproduction Auto-added tag on create to tell bot to check recreation URL, removed after check. label Mar 7, 2025
@r1tsuu
Copy link
Member

r1tsuu commented Mar 7, 2025

Can you try that on 3.27.0?

@maxkarkowski
Copy link
Author

maxkarkowski commented Mar 7, 2025

Can you try that on 3.27.0?

@r1tsuu already did. still the same error

@r1tsuu
Copy link
Member

r1tsuu commented Mar 10, 2025

What if you sync indexes for the courses collection? Create a migration with pnpm payload migrate:create and write there:

await payload.db.collections.courses.syncIndexes()

The only change that we did is that now if you have a join field - the target relationship is indexed by default. I think it shouldn't cause any issues though.

@maxkarkowski
Copy link
Author

maxkarkowski commented Mar 11, 2025

What if you sync indexes for the courses collection? Create a migration with pnpm payload migrate:create and write there:

await payload.db.collections.courses.syncIndexes()

The only change that we did is that now if you have a join field - the target relationship is indexed by default. I think it shouldn't cause any issues though.

where exactly should i append the syncIndexex() function?. do i need to run another migrate command after that?

i added the line of code to the migration file and run payload migrate.

Image

then i run pnpm run dev again but still the same issue.

I even did npm run payload migrate:fresh and drop my whole database with it. after creating a new course and a new organizer the error still occurs

when i delete the join field in the organizer collection it works, so the only way for now is to get rid of my join fields

@maxkarkowski
Copy link
Author

anyway you could help with that?

@github-actions github-actions bot added the stale label Apr 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale status: needs-triage Possible bug which hasn't been reproduced yet
Projects
None yet
Development

No branches or pull requests

2 participants