Repository navigation
Check smallint columns against their signed or unsigned range - #800
Conversation
|
looks like this repo needs a separate PR first to fix PHP 8.3 build. could you look into it? thank you. |
40a1b10 to
e17d412
Compare
|
Thanks @staabm! Looks like @ondrejmirtes beat me to it with #803 (I had landed on the same patch changes, so at least we agree 😄). I rebased this PR on top of it, so the build should be green now, including Mutation Testing. |
|
//cc @SanderMuller |
|
I checked this locally with DBAL 3.10 and ORM 2.20. The reporter's attribute snippet is reported on 2.1.x and is clean with this PR. The new test fails on 2.1.x with the 6 errors from the description. The change adds no new errors, because it only narrows the type the database can return. One small thing: DBAL 3 casts I found no measurable performance difference. |
|
thank you! |
Closes #672
EntityColumnRulenow knows that asmallintcolumn can only holdint<-32768, 32767>, orint<0, 65535>when it is mapped withoptions: {unsigned: true}. A property typed with that range no longer gets "database can contain int but property expects int<-32768, 32767>", and a range that does not match the column (an unsigned range on a signed column, or the other way round) is reported.I did it in the rule rather than in
SmallIntTypeas suggested in the issue, because the descriptor does not see the column options: a fixed signed range there would also narrow DQL results, which would be wrong for unsigned MySQL columns. If you'd rather have the descriptor returnint<-32768, 65535>too (correct for both), I'm happy to add it with a query result test.The new test fails on
2.1.xwith the error from the issue on 6 of its properties. I also checked by hand that the usual mutants on the new lines (instanceof,??,=== true, the ternary, each bound ±1) are all caught, since I couldn't run Infection locally. ODM tests were not run here (noext-mongodb).