inserting null on an autoincrement primary key prevents cleanup

Open
#58 0 comments 0 reactions 0 assignees View on GitHub

@jtopenpetition is already working on this.

Since Jun 14, 2023.

  • #57 by @jtopenpetition — open

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
38/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
php

Research direction

Start by reproducing the haveInDatabase(table, ['id' => null, ...]) case with an autoincrement primary key, then trace how the inserted ID is recorded for teardown cleanup. Done means the generated primary-key value is retained and the inserted row is removed during cleanup without breaking cases where the autoincrement column is not the primary key.

Written by the indexing model from the issue text.

Description

When I have a table with a primary key column that's also increment, it's valid to set it to null on the insert statement. the last insert it will then return the auto increment value, which is the primary key in that case.

As already noticed in #44, the auto increment column doesn't have to be part of the primary key, so the return value of last insert id ironically doesn't necessarily belong to the primary key. However, #44 also broke the case, which one might perceive as more common, that the last insert id may also be the primary key.

So, haveInDatabase(table, ['id' => null, ...]) with id as autoincrement and pk will lead to the id being set to null for cleanup, which results in the row not being removed at teardown.

I have prepared a fix for this case, which hopefully is specific enough to not interfere with other use cases.

Dominant language
PHP
Stars
23
Forks
31
PR merge metrics
No merged PRs in 30d

Getting set up

  • Ships a Dockerfile or Docker Compose file
  • No pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Codeception/module-db

All issues in Codeception/module-db

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.