Codeception / Codeception/module-db
haveInDatabase() is not usable inside a transaction on PostgreSQL
- Dominant language
- PHP
- Stars
- 23
- Forks
- 31
- PR merge metrics
- No merged PRs in 30d
Description
Our tables have PK sequences with different names than the ones postgres generates automatically. Because of that the lastInsertId() call inside haveInDatabase() generates a silent error.
When you use the method in a transaction, you don't see the actual error but the transaction is marked as "aborted" and you get exception and test fail on the next db statement. Without a transaction the test works fine but leaves other residues, which I hoped to clear by rollback. It took some time to debug and find the actual cause.
I did not find any warning about such limitation or previous mentions of it.
As a workaround I used INSERT .. RETURNING.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start at the haveInDatabase() entry point and trace the lastInsertId() call when PostgreSQL is used inside a transaction. Reproduce the case with a primary-key sequence whose name differs from PostgreSQL's generated name, then verify that the database statement succeeds without silently aborting the transaction and that subsequent statements do not fail.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php, postgresql
- Domain
- database, testing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100