On Fluent Models and Sendable warnings

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.

blog.vapor.codes/posts/fluent-models-and-sendable/

Since FluentKit 1.48.0, users have encountered a warning about mutable stored properties in Sendable-conforming Model classes due to Swift’s concurrency requirements and property wrapper limitations.

The recommended fix is to add @unchecked Sendable to Model, ModelAlias, Schema, or Fields types to suppress the warning, as Fluent’s property wrappers require mutable setters and its class-based models cannot be made inherently Sendable without breaking compatibility.

This is a compromise, as models aren’t truly thread-safe, but alternatives like @preconcurrency import Fluent are unreliable due to @_exported issues and overly broad. The solution balances maintaining Fluent’s functionality with Swift 6’s strict concurrency checks, though it incurs performance trade-offs, with a proper fix planned for Fluent 5.


Category:

Year: