On Fluent Models and Sendable warnings

The situation with Fluent Models and Sendable warnings

On Fluent Models and Sendable warnings

Many users have noticed that since the release of FluentKit 1.48.0 almost a month ago, every one of their Model types is afflicted by a new warning:

Stored property '_id' of 'Sendable'-conforming class 'SomeModel' is mutable

The TL;DR version: There's a corner case in Swift when property wrappers are used by classes that makes it impossible to satisfy Sendable's requirements, but Fluent has to require Sendable models in order to satify those requirements itself. Users can and should suppress the warning by adding @unchecked Sendable conformance to each individual type conforming to Model, ModelAlias, Schema or Fields, as in the following example:

import Fluent

// ****** BEFORE: ******
final class SomeModel: Model {
// ****** AFTER: ******
final class SomeModel: Model, @unchecked Sendable {
    static let schema = "some_models"
    var id: UUID?
    // ...

And that's pretty much all there is to it. For those who are interested, the remainder of this post gives some more detail on how things ended up like this.

It's The Property Wrappers’ World, You're Just Living In It

A number of factors are involved in the problem and this being the chosen solution. Here's a mostly complete list:

So bascially, at the end of day, it's all a kludge, but it was the best choice out of a bunch of bad options. Even the Swift core team was helpless to suggest anything better when I brought the problem to them. I promise to fix it for real in Fluent 5!

P.S.: Speaking of Fluent 5, stay tuned for updates on that subject in the near future 😶