Repository navigation
fix: Accept set literals in inSet and notInSet on id columns - #5948
Merged
FXschwartz merged 3 commits intoNov 25, 2026
Merged
Conversation
Generated tables extend `Table<int?>`, so `t.id` is typed `ColumnComparable<int?>` and a set literal passed to `inSet` is a `Set<int?>`. The column was a `ColumnInt` cast to that type, whose `inSet(Set<int>)` rejected the set at run time. Build the id column as a subclass of `ColumnInt` or `ColumnUuid` whose set operations take `Set<T?>`, treating null like `equals(null)` does.
FXschwartz
requested changes
Nov 24, 2026
FXschwartz
left a comment
Collaborator
There was a problem hiding this comment.
Hey @BiAksoy, thanks for digging into this one! The fix looks good to me and I couldn't find any other column that has the same static/runtime mismatch.
Just one super minor nit from my side:
FXschwartz
approved these changes
Nov 25, 2026
FXschwartz
left a comment
Collaborator
There was a problem hiding this comment.
LGTM! Thanks again @BiAksoy
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
t.id.inSet({...})andt.id.notInSet({...})throwtype '_Set<int?>' is not a subtype of type 'Set<int>' of 'values'(or theUuidValueequivalent) when the set literal is not given an explicit type. Generated tables extendTable<int?>, sot.idis statically aColumnComparable<int?>and the literal is inferred as aSet<int?>, but theTableconstructor builds aColumnIntand casts it to that type:serverpod/packages/serverpod_database/lib/src/concepts/table.dart
Lines 100 to 118 in 0bd8e09
The cast succeeds, and the run-time check of
inSet(Set<int> values)then rejects theSet<int?>.This PR builds the id column as
ColumnIntIdorColumnUuidId, subclasses ofColumnIntandColumnUuidwhoseinSetandnotInSettake aSet<T?>. Widening the parameter is a valid override, and it makes the run-time parameter type match what callers ofColumnComparable<int?>already pass. They stay aColumnIntand aColumnUuid, so the adapters'is ColumnIntchecks keep working:serverpod/packages/serverpod_database/lib/src/adapters/sqlite/database_connection.dart
Line 246 in 0bd8e09
serverpod/packages/serverpod_database/lib/src/adapters/postgres/database_connection.dart
Line 1093 in 0bd8e09
Since the static type admits null, the overrides handle it the way
equals(null)andnotEquals(null)do. That matters for the id of a table joined through an optional relation, which is null when the relation is not set:t.mayor.id.inSet({alex.id, null})builds(... IN (...) OR ... IS NULL), andnotInSetwith a null builds(... NOT IN (...) AND ... IS NOT NULL). Sets without null produce the same SQL as before.Other columns are not affected: a field such as
int? companyIdis generated as aColumnInt, so itsinSetalready takes aSet<int>statically, and the analyzer rejects aSet<int?>. Generated tables declare every other column with the class it is built as;t.idis the only one declared with a different type argument. On it,inSetandnotInSetare the only operations whose run-time parameter type is narrower than the static one:equalsandnotEqualstakeint?either way, and the comparison operators takedynamic.The two classes are marked
@internaland hidden from the package export; onlyTablecreates them.castToIdType()is left as it is: it is public, and the adapters still need it, because the ids they read from aTableRowaredynamicand would otherwise form aSet<dynamic>.Before, the new unit test for
Table<int?>:After:
The fix and its unit tests are the first commit, the integration tests the second.
Tests:
packages/serverpod_database/test/columns/column_id_test.dartchecks the SQL thatinSetandnotInSetbuild on the id column ofTable<int?>(with and without null in the set, and with an empty set) and ofTable<UuidValue?>. 10 of its 12 tests fail onmainwith the error above. The remaining two, onTable<UuidValue>, already passed and check that a non-nullable id is unchanged.test_integration/column_operations/column_id_test.dartinserverpod_test_serverand inserverpod_test_sqlite_serverrunsinSetandnotInSeton anintid (TownInt), on aUuidValueid (CompanyUuid), and on the id of an optional relation with null in the set (TownInt.mayor). All six fail onmainwith the type error, on PostgreSQL and on SQLite.With the change, the
serverpod_databaseunit tests pass (dart test -x integration), as dotest_integration/column_operationsandtest_integration/database_operationsofserverpod_test_serveron embedded PostgreSQL (-x redis). In the fullserverpod_test_sqlite_serverintegration suite, two tests intest_tools/ephemeral_database_test.dartfail on macOS, with and without this change, because they compare a temp path under/varwith the resolved/private/varpath.Fixes #5947.
Pre-launch Checklist
///), and made sure that the documentation follows the same style as other Serverpod documentation. I checked spelling and grammar.Breaking changes
None. Calls that compiled before compile the same way, and sets without null produce the same SQL.
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.