Skip to content

One changed field led to db nuke due to orm/payload unexpected error [reproducible] [postgresql] #12512

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
seccentral opened this issue May 22, 2025 · 1 comment
Labels
status: needs-triage Possible bug which hasn't been reproduced yet

Comments

@seccentral
Copy link

Describe the Bug

Changing a field on a collection led to others (unreferenced, unrelated, with no relationship) being nuked :

         {
           name: 'tipApel',
           label: 'Tip apel',
           type: 'select',
           required: true,
           options: tipApelOptions,
           hooks: {
             afterRead: [resolveTipApelLabel],
           },
         },

changed to

  {
          name: 'tipApel',
          type: 'group',
          fields: [
            {
              type: 'row',
              fields: [
                {
                  name: 'title',
                  localized: true,
                  type: 'text',
                  required: true,
                },
                {
                  name: 'type',
                  type: 'select',
                  required: true,
                  options: tipApelOptions,
                  hooks: {
                    afterRead: [resolveTipApelLabel],
                  },
                },
              ],
            },
          ],
        },

leads to this

[✓] Pulling schema from database...
✔ Warnings detected during schema push: 
 
· You're about to add not-null informatii_generale_tip_apel_title column without default value, which contains 3 items
· You're about to add not-null informatii_generale_tip_apel_type column without default value, which contains 2 items
 
DATA LOSS WARNING: Possible data loss detected if schema is pushed.
 
Accept warnings and push schema to database? … yes
 ⨯ [error: insert or update on table "footer_blocks_contact_block" violates foreign key constraint "footer_blocks_contact_block_financed_by_link_to_page_id_pages_i"] {
  length: 717,
  severity: 'ERROR',
  code: '23503',
  detail: 'Key (financed_by_link_to_page_id)=(6) is not present in table "pages".',
  hint: undefined,
  position: undefined,
  internalPosition: undefined,
  internalQuery: undefined,
  where: 'SQL statement "ALTER TABLE "footer_blocks_contact_block" ADD CONSTRAINT "footer_blocks_contact_block_financed_by_link_to_page_id_pages_id_fk" FOREIGN KEY ("financed_by_link_to_page_id") REFERENCES "public"."pages"("id") 
ON DELETE set null ON UPDATE no action"\n' +
    'PL/pgSQL function inline_code_block line 2 at SQL statement',
  schema: 'public',
  table: 'footer_blocks_contact_block',
  column: undefined,
  dataType: undefined,
  constraint: 'footer_blocks_contact_block_financed_by_link_to_page_id_pages_i',
  file: 'ri_triggers.c',
  line: '2599',
  routine: 'ri_ReportViolation',
  digest: '3597499009'
}
 ⨯ [error: insert or update on table "footer_blocks_contact_block" violates foreign key constraint "footer_blocks_contact_block_financed_by_link_to_page_id_pages_i"] {
  length: 717,
  severity: 'ERROR',
  code: '23503',
  detail: 'Key (financed_by_link_to_page_id)=(6) is not present in table "pages".',
  hint: undefined,
  position: undefined,
  internalPosition: undefined,
  internalQuery: undefined,
  where: 'SQL statement "ALTER TABLE "footer_blocks_contact_block" ADD CONSTRAINT "footer_blocks_contact_block_financed_by_link_to_page_id_pages_id_fk" FOREIGN KEY ("financed_by_link_to_page_id") REFERENCES "public"."pages"("id") 
ON DELETE set null ON UPDATE no action"\n' +
    'PL/pgSQL function inline_code_block line 2 at SQL statement',
  schema: 'public',
  table: 'footer_blocks_contact_block',
  column: undefined,
  dataType: undefined,
  constraint: 'footer_blocks_contact_block_financed_by_link_to_page_id_pages_i',
  file: 'ri_triggers.c',
  line: '2599',
  routine: 'ri_ReportViolation',
  digest: '3597499009'
}
 ⨯ [error: insert or update on table "footer_blocks_contact_block" violates foreign key constraint "footer_blocks_contact_block_financed_by_link_to_page_id_pages_i"] {
  length: 717,
  severity: 'ERROR',
  code: '23503',
  detail: 'Key (financed_by_link_to_page_id)=(6) is not present in table "pages".',
  hint: undefined,
  position: undefined,
  internalPosition: undefined,
  internalQuery: undefined,
  where: 'SQL statement "ALTER TABLE "footer_blocks_contact_block" ADD CONSTRAINT "footer_blocks_contact_block_financed_by_link_to_page_id_pages_id_fk" FOREIGN KEY ("financed_by_link_to_page_id") REFERENCES "public"."pages"("id") 
ON DELETE set null ON UPDATE no action"\n' +
    'PL/pgSQL function inline_code_block line 2 at SQL statement',
  schema: 'public',
  table: 'footer_blocks_contact_block',
  column: undefined,
  dataType: undefined,
  constraint: 'footer_blocks_contact_block_financed_by_link_to_page_id_pages_i',
  file: 'ri_triggers.c',
  line: '2599',
  routine: 'ri_ReportViolation',
  digest: '3597499009'
} 

Consequence : - footer global, pages collection gets wiped.
Expected : local field in original collection changes, nothing else affected.

Link to the code that reproduces this issue

can't share

Reproduction Steps

Attempted to directly change the field and push changes -> nuked.
Attempted to delete the field, push the deletion -> works -> add the new field, push the addition -> nuked
Changed from turbopack to webpack -> still nuked
db backend (PostgreSQL) 17.4 (Debian 17.4-1.pgdg120+2) dockerized
payloadcms version : 3.38.0

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

db-postgres

Environment Info

Payload: 3.38.0 
Node: 22.15.1
next: 15.3.2
@seccentral seccentral 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 May 22, 2025
Copy link
Contributor

Please add a reproduction in order for us to be able to investigate.

Depending on the quality of reproduction steps, this issue may be closed if no reproduction is provided.

Why was this issue marked with the invalid-reproduction label?

To be able to investigate, we need access to a reproduction to identify what triggered the issue. We prefer a link to a public GitHub repository created with create-payload-app@latest -t blank or a forked/branched version of this repository with tests added (more info in the reproduction-guide).

To make sure the issue is resolved as quickly as possible, please make sure that the reproduction is as minimal as possible. This means that you should remove unnecessary code, files, and dependencies that do not contribute to the issue. Ensure your reproduction does not depend on secrets, 3rd party registries, private dependencies, or any other data that cannot be made public. Avoid a reproduction including a whole monorepo (unless relevant to the issue). The easier it is to reproduce the issue, the quicker we can help.

Please test your reproduction against the latest version of Payload to make sure your issue has not already been fixed.

I added a link, why was it still marked?

Ensure the link is pointing to a codebase that is accessible (e.g. not a private repository). "example.com", "n/a", "will add later", etc. are not acceptable links -- we need to see a public codebase. See the above section for accepted links.

Useful Resources

@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 May 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs-triage Possible bug which hasn't been reproduced yet
Projects
None yet
Development

No branches or pull requests

1 participant