Repository navigation
fix(postgres): read the sequence only for a document created without one - #1021
Merged
Merged
Conversation
createDocument() called lastInsertId(), which PostgreSQL answers with lastval(), after every insert. A document that brings its own $sequence inserts it into the identity column without calling nextval(), so on a session that has not called nextval() yet lastval() raises 55000 "lastval is not yet defined in this session" and the create fails. MariaDB, MySQL and SQLite answer 0 there instead of raising. It showed up as a SharedTables/Postgres CI failure in testDeleteDocument, which re-creates its fixture with the fixture's sequence on a fresh paratest process. The sequence is now read only when the document has none, as the value was already kept in that case. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 9 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Postgres::createDocument()callslastInsertId()after every insert, and PostgreSQL answers that withlastval(). A document that brings its own$sequencewrites it into the identity column without callingnextval(). On a session that has not callednextval()yet,lastval()raises:So creating a document with its own sequence on a fresh connection fails. Restores and migrations re-create documents with their sequence. MariaDB, MySQL and SQLite answer
0in the same case instead of raising, and they already read the sequence only when it is missing.It surfaced as a SharedTables/Postgres failure in
testDeleteDocumenton #1019 (job). That test re-creates its fixture with the fixture's own sequence, and paratest--functionalgives each test a fresh process.Fix
Read
lastInsertId()only when the document has no sequence. When it has one, the value was already kept by the old??=.Test
DocumentTests::testDocumentRecreatedWithItsSequenceInAFreshSessionKeepsItcreates a document, deletes it, and re-creates it with its sequence. On PostgreSQL it first runsDISCARD SEQUENCES, which clears the session'slastval(), so the failure no longer depends on test order. The test checks that the re-created document and a fresh read keep the original sequence.Run locally against PostgreSQL 18, the test fails on
mainwith the error above and passes with the fix.testCreateDocument*/testDeleteDocument*(33 tests) pass on PostgreSQL, and the new test passes on SQLite. Pint and PHPStan are clean on the changed files.🤖 Generated with Claude Code