Skip to content
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

Saving a post with Select with hasMany in a Block will cause Sqlite error #10780

Open
blueset opened this issue Jan 24, 2025 · 0 comments
Open
Assignees

Comments

@blueset
Copy link

blueset commented Jan 24, 2025

Describe the Bug

When a collection is set up to have a block which include a Select field with hasMany enabled, any value added to the Select field would cause a SQLite foreign key constraint failure.

Repro setup: blueset@e917804

Error message:

ERROR: There was an error while saving a version for the Post with ID 1.
    err: {
      "type": "Error",
      "message": "FOREIGN KEY constraint failed",
      "stack":
          Error: FOREIGN KEY constraint failed
              at Object.next (payload\node_modules\.pnpm\[email protected]\node_modules\libsql\index.js:335:20)
              at Statement.all (payload\node_modules\.pnpm\[email protected]\node_modules\libsql\index.js:360:16)
              at executeStmt (payload\node_modules\.pnpm\@[email protected][email protected][email protected]\node_modules\@libsql\client\lib-cjs\sqlite3.js:285:34)    
              at Sqlite3Client.execute (payload\node_modules\.pnpm\@[email protected][email protected][email protected]\node_modules\@libsql\client\lib-cjs\sqlite3.js:101:16)
              at LibSQLPreparedQuery.values (payload\node_modules\.pnpm\[email protected]_@[email protected][email protected][email protected]__@neondatabase_6resdlyducyo6357g5vrmmkeri\node_modules\src\libsql\session.ts:262:57)
              at LibSQLPreparedQuery.all (payload\node_modules\.pnpm\[email protected]_@[email protected][email protected][email protected]__@neondatabase_6resdlyducyo6357g5vrmmkeri\node_modules\src\libsql\session.ts:191:27)
              at QueryPromise.all (payload\node_modules\.pnpm\[email protected]_@[email protected][email protected][email protected]__@neondatabase_6resdlyducyo6357g5vrmmkeri\node_modules\src\sqlite-core\query-builders\insert.ts:355:26)
              at QueryPromise.execute (payload\node_modules\.pnpm\[email protected]_@[email protected][email protected][email protected]__@neondatabase_6resdlyducyo6357g5vrmmkeri\node_modules\src\sqlite-core\query-builders\insert.ts:367:40)
              at QueryPromise.then (payload\node_modules\.pnpm\[email protected]_@[email protected][email protected][email protected]__@neondatabase_6resdlyducyo6357g5vrmmkeri\node_modules\src\query-promise.ts:31:15)
      "rawCode": 787,
      "code": "SQLITE_CONSTRAINT_FOREIGNKEY",
      "libsqlError": true
    }

TypeError: Cannot read properties of undefined (reading 'title')
    at promise (payload\packages\payload\src\fields\hooks\afterRead\promise.ts:133:22)
    at payload\packages\payload\src\fields\hooks\afterRead\traverseFields.ts:75:14
    at Array.forEach (<anonymous>)
    at forEach (payload\packages\payload\src\fields\hooks\afterRead\traverseFields.ts:73:10)
    at afterRead (payload\packages\payload\src\fields\hooks\afterRead\index.ts:71:17)
    at updateDocument (payload\packages\payload\src\collections\operations\utilities\update.ts:320:27)
    at updateByIDOperation (payload\packages\payload\src\collections\operations\updateByID.ts:165:18)
    at Object.<anonymous> (payload\test\_community\int.spec.ts:52:21)

Link to the code that reproduces this issue

https://github.com/blueset/payload/blob/select-in-block-bug/test/_community/int.spec.ts

Reproduction Steps

git clone https://github.com/blueset/payload
git switch select-in-block-bug
pnpm test:int:sqlite "_Community"

Observe the test failure.

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

db-sqlite

Environment Info

Binaries:
  Node: 23.6.0
  npm: N/A
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  payload: 3.18.0
  next: 15.1.5
  @payloadcms/email-nodemailer: 3.18.0
  @payloadcms/graphql: 3.18.0
  @payloadcms/live-preview: 3.18.0
  @payloadcms/live-preview-react: 3.18.0
  @payloadcms/next/utilities: 3.18.0
  @payloadcms/payload-cloud: 3.18.0
  @payloadcms/plugin-form-builder: 3.18.0
  @payloadcms/plugin-nested-docs: 3.18.0
  @payloadcms/plugin-redirects: 3.18.0
  @payloadcms/plugin-search: 3.18.0
  @payloadcms/plugin-seo: 3.18.0
  @payloadcms/richtext-lexical: 3.18.0
  @payloadcms/translations: 3.18.0
  @payloadcms/ui/shared: 3.18.0
  react: 19.0.0
  react-dom: 19.0.0
Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Pro
  Available memory (MB): 95801
  Available CPU cores: 32
@blueset blueset added status: needs-triage Possible bug which hasn't been reproduced yet validate-reproduction labels Jan 24, 2025
@DanRibbens DanRibbens self-assigned this Jan 24, 2025
@github-actions github-actions bot removed the status: needs-triage Possible bug which hasn't been reproduced yet label Jan 24, 2025
@DanRibbens DanRibbens assigned r1tsuu and unassigned DanRibbens Jan 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants