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
24.94k stars 1.59k forks source link

ERROR: APIError: Cannot find field for path at _status #8512

Closed mikecebul closed 1 month ago

mikecebul commented 1 month ago

Link to reproduction

No response

Environment Info

Binaries:
  Node: 20.14.0
  npm: 10.7.0
  Yarn: 1.22.22
  pnpm: 9.1.4
Relevant Packages:
  payload: 3.0.0-beta.110
  next: 15.0.0-canary.160
  @payloadcms/email-resend: 3.0.0-beta.110
  @payloadcms/graphql: 3.0.0-beta.110
  @payloadcms/live-preview: 3.0.0-beta.110
  @payloadcms/live-preview-react: 3.0.0-beta.110
  @payloadcms/next/utilities: 3.0.0-beta.110
  @payloadcms/plugin-cloud-storage: 3.0.0-beta.110
  @payloadcms/plugin-form-builder: 3.0.0-beta.110
  @payloadcms/plugin-redirects: 3.0.0-beta.110
  @payloadcms/plugin-seo: 3.0.0-beta.110
  @payloadcms/plugin-stripe: 3.0.0-beta.110
  @payloadcms/richtext-lexical: 3.0.0-beta.110
  @payloadcms/storage-s3: 3.0.0-beta.110
  @payloadcms/translations: 3.0.0-beta.110
  @payloadcms/ui/shared: 3.0.0-beta.110
  react: 19.0.0-rc-5dcb0097-20240918
  react-dom: 19.0.0-rc-5dcb0097-20240918
Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP Fri Mar 29 23:14:13 UTC 2024
  Available memory (MB): 15847
  Available CPU cores: 16

Describe the Bug

I'm using Sqlite and the FormBuilder Plugin. When I create a form submission when not logged in it creates a form submissions but it but gives this error:

POST /api/form-submissions 500 in 878ms
[17:44:11] ERROR: APIError: Cannot find field for path at _status
    at getTableColumnFromPath (webpack-internal:///(rsc)/./node_modules/.pnpm/@payloadcms+drizzle@3.0.0-beta.110_@libsql+client@0.6.2_payload@3.0.0-beta.110_graphql@16.9.0_e46uqquvsphcwhzpgzplorasoi/node_modules/@payloadcms/drizzle/dist/queries/getTableColumnFromPath.js:592:11)
    at parseParams (webpack-internal:///(rsc)/./node_modules/.pnpm/@payloadcms+drizzle@3.0.0-beta.110_@libsql+client@0.6.2_payload@3.0.0-beta.110_graphql@16.9.0_e46uqquvsphcwhzpgzplorasoi/node_modules/@payloadcms/drizzle/dist/queries/parseParams.js:56:242)
    at buildAndOrConditions (webpack-internal:///(rsc)/./node_modules/.pnpm/@payloadcms+drizzle@3.0.0-beta.110_@libsql+client@0.6.2_payload@3.0.0-beta.110_graphql@16.9.0_e46uqquvsphcwhzpgzplorasoi/node_modules/@payloadcms/drizzle/dist/queries/buildAndOrConditions.js:14:88)
    at parseParams (webpack-internal:///(rsc)/./node_modules/.pnpm/@payloadcms+drizzle@3.0.0-beta.110_@libsql+client@0.6.2_payload@3.0.0-beta.110_graphql@16.9.0_e46uqquvsphcwhzpgzplorasoi/node_modules/@payloadcms/drizzle/dist/queries/parseParams.js:35:123)
    at buildQuery (webpack-internal:///(rsc)/./node_modules/.pnpm/@payloadcms+drizzle@3.0.0-beta.110_@libsql+client@0.6.2_payload@3.0.0-beta.110_graphql@16.9.0_e46uqquvsphcwhzpgzplorasoi/node_modules/@payloadcms/drizzle/dist/queries/buildQuery.js:24:77)
    at find (webpack-internal:///(rsc)/./node_modules/.pnpm/@payloadcms+drizzle@3.0.0-beta.110_@libsql+client@0.6.2_payload@3.0.0-beta.110_graphql@16.9.0_e46uqquvsphcwhzpgzplorasoi/node_modules/@payloadcms/drizzle/dist/find/findMany.js:27:119)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Reproduction Steps

Submit a form with a function like this when there is no logged in user.

const req = await fetch(`${process.env.NEXT_PUBLIC_SERVER_URL}/api/form-submissions`, {
  body: JSON.stringify({
    form: formID,
    submissionData: dataToSend,
  }),
  headers: {
    'Content-Type': 'application/json',
  },
  method: 'POST',
})

My build config is pretty complex though:

 formBuilderPlugin({
      defaultToEmail: 'mike@mikecebul.dev',
      fields: {
        payment: false,
      },
      formOverrides: {
        fields: ({ defaultFields }) => [
          {
            name: 'requirePayment',
            type: 'checkbox',
            label: 'Require Payment',
            defaultValue: false,
          },
          {
            name: 'event',
            type: 'relationship',
            relationTo: 'events',
            admin: {
              condition: (data, siblingData) => {
                if (siblingData && 'requirePayment' in siblingData) {
                  return siblingData.requirePayment === true
                }
                return false
              },
            },
          },
          ...defaultFields.map((field) => {
            if ('name' in field && field.name === 'confirmationMessage') {
              return {
                ...field,
                editor: lexicalEditor({
                  features: ({ defaultFeatures }) => [
                    ...defaultFeatures,
                    FixedToolbarFeature(),
                    HeadingFeature({ enabledHeadingSizes: ['h1', 'h2', 'h3', 'h4'] }),
                  ],
                }),
              }
            }
            return field
          }),
          {
            name: 'submissions',
            type: 'join',
            collection: 'form-submissions',
            on: 'form',
          },
        ],
      },
      formSubmissionOverrides: {
        fields: ({ defaultFields }) => {
          return defaultFields
            .map((field) => {
              if (field.type === 'array') {
                return {
                  ...field,
                  admin: {
                    ...field.admin,
                    components: {
                      RowLabel: '@/fields/form-submissions/FormSubmissionRowLabel',
                    },
                  },
                }
              }
              return field
            })
            .concat([
              {
                name: 'paymentStatus',
                label: 'Payment Status',
                type: 'text',
                defaultValue: 'pending',
                admin: {
                  position: 'sidebar',
                },
              },
              {
                name: 'amount',
                label: 'Amount Paid',
                type: 'text',
                admin: {
                  position: 'sidebar',
                },
              },
            ])
        },
      },
    }),

Adapters and Plugins

db-sqlite, plugin-form-builder

mikecebul commented 1 month ago

I've tracked this down to me passing a relationship field in the form. When not logged in the form works if I don't pass an event in my relationship field. It works if I leave the field blank. When logged in it works as expected. I can pass an event into the form and submit the form.

mikecebul commented 1 month ago

I think I'm going to throw up. All I needed was to allow read access to anyone on my collection of events that i injected into the form.

github-actions[bot] commented 1 month ago

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