Skip to content

fix(db): remove an impossible lastInsertId fallback and a duplicate getter - #3236

Merged
rubenvdlinde merged 1 commit into
developmentfrom
fix/impossible-lastinsertid-fallback-and-duplicate-getter
Aug 31, 2026
Merged

fix(db): remove an impossible lastInsertId fallback and a duplicate getter#3236
rubenvdlinde merged 1 commit into
developmentfrom
fix/impossible-lastinsertid-fallback-and-duplicate-getter

Conversation

@rubenvdlinde

Copy link
Copy Markdown
Contributor

Two more baseline entries that turned out to be real defects. 184 -> 180.

A fallback that could never run

$pollId = (int)$this->db->lastInsertId("oc_polls_polls_id_seq");
if ($pollId === 0) {
    // Fallback for drivers without sequence support.
    $pollId = (int)$this->db->lastInsertId();
}

OCP\IDBConnection::lastInsertId(string $table): int takes a required argument. The no-arg call raises ArgumentCountError on precisely the drivers the fallback existed for, and the surrounding catch (Throwable) reported it as Failed to create poll — blaming the insert rather than the id retrieval. A zero now falls through to the explicit throw that was already there.

I checked the other four lastInsertId call sites: MagicMapper and DedupCollidedSchemasCommand pass a table; DbalObjectSourceProvider calls it with no argument but on a DBAL Connection, where the parameter is optional. Psalm flagged only the one that was wrong.

A getter declared twice

@method string|null getToken()
@method void getToken(?string $token)   <- copy-paste of the setter
@method void setToken(?string $token)

Psalm binds to the second declaration, which is why two perfectly correct $row->getToken() calls read as Too few arguments. Removed; setToken on the next line was already correct. I swept all of lib/Db for the same slip and this was the only instance.

Verification

vendor/bin/psalm 5.26.1 on PHP 8.3: all four TooFewArguments gone, errors with the baseline emptied went 184 -> 180, regenerated baseline green.

PHPUnit not run locally (needs the server bootstrap). No constructor signatures changed here, so there is no positional-argument shift to check this time.

…etter

Two more entries the Psalm baseline was carrying. Both are real. 184 -> 180.

PollLinkService had a fallback that could never run:

    $pollId = (int)$this->db->lastInsertId("oc_polls_polls_id_seq");
    if ($pollId === 0) {
        // Fallback for drivers without sequence support.
        $pollId = (int)$this->db->lastInsertId();
    }

OCP\IDBConnection::lastInsertId(string $table): int takes a REQUIRED
argument, so the no-arg call raises ArgumentCountError on exactly the
drivers the fallback was written for. The surrounding catch (Throwable)
turned that into "Failed to create poll", which blames the insert rather
than the id retrieval. A zero now falls through to the explicit throw that
was already there and says what actually happened.

Checked the other four lastInsertId call sites. MagicMapper and
DedupCollidedSchemasCommand pass a table. DbalObjectSourceProvider calls it
with no argument, but on a DBAL Connection rather than IDBConnection, where
the parameter is optional. Psalm flagged only the one that was wrong.

CaseToken declared getToken TWICE:

    @method string|null getToken()
    @method void getToken(?string $token)   <- copy-paste of the setter
    @method void setToken(?string $token)

Psalm binds to the second, which is why two correct $row->getToken() calls
read as "Too few arguments". Removed; setToken on the next line was already
right. Swept lib/Db for the same slip: this was the only one of them.

Verified with the repo own vendor/bin/psalm 5.26.1 on PHP 8.3: all four
TooFewArguments are gone, errors with the baseline emptied went 184 -> 180,
regenerated baseline is green. PHPUnit was NOT run here, it needs the
Nextcloud server bootstrap that only exists inside a server checkout.
@github-actions

Copy link
Copy Markdown
Contributor

Quality Report — ConductionNL/openregister @ bbc272d

Check PHP Vue Security License Tests
lint
phpcs
phpmd
psalm
phpstan
phpmetrics
eslint
stylelint
build
check-specs
test-l10n
test-l10n-parity
format
check-schema-l10n
check-l10n-js
composer ✅ 174/174
npm ✅ 543/543
app:check-code ⏭️
info.xml
REUSE
PHPUnit
Newman
Playwright ⏭️ deferred — runs on the promotion into beta/main, not on a pull request into development
Hydra gates

Quality workflow — 2026-08-31 17:11 UTC

Download the full PDF report from the workflow artifacts.

@rubenvdlinde
rubenvdlinde merged commit 07b58b0 into development Aug 31, 2026
47 checks passed
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

Successfully merging this pull request may close these issues.

1 participant