Repository navigation
fix: Allow only defaultPersist and defaultModel keys on id field - #3416
Conversation
…rsist default keys
… forcing nullable
@marcelomendoncasoares Should a UUID with Personally I would also think this is nicer for the "notes use-case" described somehwere, where you want to link UUIDs locally before having them persisted. In that case it'd be very nice to use Just my 2 cents, maybe you and @SandPod found some good reasons why we could not support opt-in non- Edit: I think there is also always the slight mismatch in the types / behaviors anyway, in that an |
I agree with you and even tried this as first implementation, but had to revert it (note the commit #45d6efc) due to the abstract /// Holds data corresponding to a row in the database. Concrete classes are
/// typically generated. Instances of [TableRow] can also be serialized and
/// either passed to clients or cached.
abstract interface class TableRow<T_ID> implements SerializableModel {
TableRow(this.id); // <-- Add a constructor due to the id field being possibly non-nullable
/// The id column of the row. Can be null if this row is not yet stored in
/// the database.
T_ID id; // <-- Remove the '?' from here
/// The table that this row belongs to.
Table<T_ID> get table;
}And change the generator to pass the type as nullable on each model, like this: abstract class AuthKey
implements _i1.TableRow<int?>, _i1.ProtocolSerialization { // <-- Add the nullable '?' to "int" here
AuthKey._({
this.id,
required this.userId,
required this.hash,
this.key,
required this.scopeNames,
required this.method,
});This, however simple, is a breaking change. It will require re-generating all table class models (including the ones on auth and chat modules). So I though it would be better not to couple the change to this PR, since we could treat "enable non-nullable id field" as a separate feature. But I would have no problem adding it to this PR if we understand it to be better. |
I think this change would be OK. Since we have a strict version requirement all To me, it sounds like basically the same change as when we went from This STILL is probably best introduced in a separate PR, non-nullable id field if |
SandPod
left a comment
There was a problem hiding this comment.
Nice work!
Would you like to explore the possibility to remove nullability when defaultModel is defined in this PR or in a separate one? Otherwise all changes here look good except for some minor questions. 👍
I also prefer to tackle it in a separate PR, to keep the fix here well scoped. The change is simple and is already tested, but I think we will be able to validate it better separately. |
SandPod
left a comment
There was a problem hiding this comment.
LGTM! 👍
Single suggestion to fix in the test then we an merge it.
|
Created an issue for the non-nullable id field: #3429 @marcelomendoncasoares If you comment on it I can assign it to you. |
|
@SandPod, I see we have a failing test, but it is not related to the change in the last commit, right? It happened yesterday between pushes as well, and disappeared after a new run. Locally, all tests are passing normally, such as with most of the CI runs. Is it a known bug that the |
|
@marcelomendoncasoares - No, this is a flaky test in |
As discussed on #3396, this PR removes the possibility of the user to declare an
idfield using thedefaultkeyword. This forces the user to decide whether to have UUID values being defined on the model (using thedefaultModelkeyword) or only on the database (using thedefaultPersistkeyword).While making such change, it became clear that we were allowing the user to declare the type as non-nullable, but the resulting type was always set as nullable (as required by the
TableRow.idmodel). This is now fixed, with the user being required to declare theidtype as nullable (such as already happens when declaring foreign key fields).Closes: #3396
Pre-launch Checklist
///), and made sure that the documentation follows the same style as other Serverpod documentation. I checked spelling and grammar.If you need help, consider asking for advice on the discussion board.
Breaking changes
No breaking changes.