Selection: insert() phpDoc covers documented bulk form#326
Open
haltuf wants to merge 1 commit intonette:v3.2from
Open
Selection: insert() phpDoc covers documented bulk form#326haltuf wants to merge 1 commit intonette:v3.2from
haltuf wants to merge 1 commit intonette:v3.2from
Conversation
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.
Branched from tag
v3.2.9; opening againstv3.2branch per GitHub requirement (tags can't be PR base). Twov3.2commits ahead are independent — rebase on request.Regression
Commit 420ebb5 (v3.2.9) narrowed
Selection::insert()phpDoc:This rejects the documented bulk form
$table->insert([[...], [...]])(list<array<string, mixed>>is not assignable toiterable<string, mixed>).Reported on forum: https://forum.nette.org/cs/36954
Runtime check (SQLite, MySQL 8, MariaDB 11, PostgreSQL 16)
Ran
insert()across primary-key scenarios on all four drivers. All drivers return the same PHP types (only ID values differ for bulk + autoincrement due toLAST_INSERT_IDsemantics):ActiveRowActiveRowActiveRowarray(input data)int(row count)ActiveRow(first or last inserted, driver-dependent)intarray(input data)intintThe v3.2.9 conditional return claims
intfor every non-array<string, mixed>path, but runtime returnsarray(bulk + multi-col) andActiveRow(bulk + autoincrement) for two of them on every driver. Runtime has been stable across v3.x.Fix
@paramextended bylist<array<string, mixed>>(documented bulk form).@returnreverted to permissive unionT|array<int|string, mixed>|intcovering every observed runtime path. Same shape as pre-v3.2.9.tests/types/database-types.php: added asserts for single-row, bulk, and from-Selection variants.tests/types/TypesTest.phpt: addedTypeAssert::assertNoErrors()so a future narrowing regression fails the test, not just a baseline phpDoc check.No runtime change.
Note on the extra
assertNoErrors()callTypeAssert::assertTypes()only verifies return types ofassertType()calls. AnassertType('int', $table->insert($bulk))passes even on the v3.2.9-regressed code, because the conditional return still evaluates tointwhen the argument type doesn't matcharray<string, mixed>. The actualargument.typeerror on the bulk call site surfaces only through file-wide PHPStan analysis, whichassertNoErrors()performs. Without it the test guards nothing against this class of regression.If you'd rather keep
TypesTest.phptsingle-purpose (justassertTypes()), I can moveassertNoErrors()to a separate.phptfile or drop the call entirely — let me know which you prefer.Docs
https://doc.nette.org/cs/database/explorer claims "bulk insert returns row count (int)" and "single-row insert without unique PK returns passed data as array", which disagree with the runtime on all four drivers in three cases (bulk + multi-col PK, bulk + autoincrement PK, single + no PK). This PR aligns phpDoc with runtime, not docs. Separate
nette/docsPR is in order — happy to open one; wanted to unblock this regression first.4.0
Same
@paramregression is present onmaster;insert()runtime code is byte-identical. Shall I open a parallel PR against master, or cherry-pick?