Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Need insight on validation error

default discord avatar
synthluvrlast year
12

I have a bug in my production Payload instance where I'm unable to add new or update existing items for a collection. I've been unable to reproduce this locally or in a development environment, the error is only occurring in production. I'd like to know if there are any ways I can debug this issue further to determine where exactly the validation is failing.



I updated to the latest version of Payload and the issue still persists. The error in the logs is:

[11:49:39] ERROR (payload): ValidationError: The following field is invalid: items.page
    at create (/app/node_modules/payload/dist/collections/operations/create.js:145:19)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async createHandler (/app/node_modules/payload/dist/collections/requestHandlers/create.js:14:21)
  • default discord avatar
    notchrlast year

    Good morning

    @1098559108212326500

    - happy to help debug, could you share your collection config?

  • default discord avatar
    synthluvrlast year
    import { CollectionConfig } from "payload/types";
    
    const Menus: CollectionConfig = {
      slug: "menus",
      admin: {
        defaultColumns: ["name", "items"],
        useAsTitle: "name",
      },
      access: {
        read: () => true,
      },
      fields: [
        {
          name: "name",
          type: "text",
          required: true,
          unique: true,
        },
        {
          name: "items",
          type: "array",
          required: true,
          maxRows: 8,
          fields: [
            {
              name: "name",
              type: "text",
              required: true,
            },
            {
              name: "page",
              type: "relationship",
              relationTo: "pages",
            },
            {
              name: "url",
              type: "text",
            },
          ],
        },
      ],
    };
    
    export default Menus;
  • default discord avatar
    notchrlast year

    hmm and pages is the slug of the other collection?

  • default discord avatar
    synthluvrlast year

    yes



    import { CollectionConfig } from "payload/types";
    import slug from "../fields/slug";
    
    const Pages: CollectionConfig = {
      slug: "pages",
      admin: {
        defaultColumns: ["title"],
        useAsTitle: "title",
      },
      access: {
        read: () => true,
      },
      fields: [
        {
          type: "tabs",
          tabs: [
            {
              label: "Content",
              fields: [
                {
                  name: "title",
                  type: "text",
                },
                {
                  name: "content",
                  type: "richText",
                },
              ],
            },
          ],
        },
        slug(),
        {
          name: "chatbox",
          type: "checkbox",
          defaultValue: true,
          admin: {
            position: "sidebar",
          },
        },
      ],
    };
    
    export default Pages;
  • default discord avatar
    notchrlast year

    I see in your screenshot that no page is selected



    Is this happening even when one is selected?

  • default discord avatar
    synthluvrlast year

    Yes. The validation is a bit random, I haven't been able to precisely reproduce. Doesn't seem to matter if I select a page or not

  • default discord avatar
    notchrlast year

    Hmm



    If you don't mind trying an idea out

  • default discord avatar
    synthluvrlast year

    I managed to create two menus without issue. I created a third menu and it started resulting in validation errors when I tried updating. If I try and create a fourth menu then validation seems to always fail

  • default discord avatar
    notchrlast year

    What if you change the name of your array field



    to something else



    change "items" to "tests" or something



    wondering if this has to do with some kind of remenants from an update to a field config in mongo



    by changing the name of the array field, i believe it is generating a new structure



    so that if there was a problematic overlap in field names from some kind of remnant



    this would bypass it

  • default discord avatar
    synthluvrlast year

    ok I'll try



    I'm getting a new error



    This seems to be an issue with how I'm running Payload. I'm trying to run Payload locally but connect to the production database



    Still getting the same error



    That's after renaming items to tests



    When I run it locally it works, but on production it keeps failing with the validation error



    I created a Menus2 collection and recreated everything successfully. It's just the original Menus collection that is having problems



    Very strange



    I dropped the menus collection entirely in MongoDB and recreated everything. Now it's working as expected. Deleting from Payload UI wasn't enough, I had to drop it from Mongo



    So I guess this is some sort of Payload bug where the data in mongo became invalid, but I cannot reproduce and don't know what caused it

  • default discord avatar
    notchrlast year
    @1098559108212326500

    Sprry I was dealing with a fire at work



    Yeah so DB migrations are not created in Payload



    And sometimes if you have an existing collection, or fields - and it gets redefined, structural issues can happen



    I'm not sure it's entirely related



    but at minimum, here are some notes I took on resolved a collection that was stuck



    https://gist.github.com/notchris/c5155073bbbb08a487b349c52f6823ae
  • default discord avatar
    synthluvrlast year

    I see. It's strange to me that the error was presented as a validation error. Seemingly everything was okay except when saving items

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.