From d5c0044342316ae269cb2e2de43ff0bcaeeb4223 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Wed, 24 Apr 2024 20:28:18 +0200 Subject: [PATCH] StrictConcurrency: fix warning in TableRecord.request(for:) --- GRDB/QueryInterface/TableRecord+Association.swift | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/GRDB/QueryInterface/TableRecord+Association.swift b/GRDB/QueryInterface/TableRecord+Association.swift index c77b00a97..46f7fe395 100644 --- a/GRDB/QueryInterface/TableRecord+Association.swift +++ b/GRDB/QueryInterface/TableRecord+Association.swift @@ -567,6 +567,19 @@ extension TableRecord where Self: EncodableRecord { fatalError("Not implemented: request association without any foreign key") case let .foreignKey(foreignKey): + // Build the sendable persistence container before building the + // request, and catch the eventual error in a Result, so that it + // is thrown later, when the request is executed. This allows + // this method to not throw: + // + // extension Player { + // // We don't want this property to have a throwing getter: + // var team: QueryInterfaceRequest { + // request(for: Player.team) + // } + // } + let persistenceContainer = Result { try PersistenceContainer(self) } + let destinationRelation = association ._sqlAssociation .with { @@ -574,7 +587,7 @@ extension TableRecord where Self: EncodableRecord { // Filter the pivot on self try foreignKey .joinMapping(db, from: Self.databaseTableName) - .joinExpression(leftRows: [PersistenceContainer(db, self)]) + .joinExpression(leftRows: [persistenceContainer.get()]) } } .destinationRelation()