SwiftData FatalError Unknown Relationship Key

Some of our users on iOS 17.5+ started to encounter crash due to: SwiftData/BackingData.swift:669: Fatal error: Unknown Relationship Key - subscription)

We have tried using SwiftData on the MainActor only but an issues still effects some of our users.

Our models look like these:

@Model
public final class ProfileModel {

    public static let fetchDescriptor = FetchDescriptor<ProfileModel>.self

    public enum Gender: Codable {
        case female
        case male
        case other
    }

    public enum Units: Codable {
        case imperial
        case metric
    }

    public enum Eating: Codable {
        case empath
        case enthusiast
        case explorer
        case guardian
        case harmonizer
        case pacifier
        case regulator
        case stoic
        case iosDefault
    }

    public enum RegistrationSource: Codable {
        case iOS
        case web
    }

    public enum NHE: Codable {
        case combined
        case emotional
        case mindless
    }

    public enum Goal: Codable {
        case beHealthier
        case energyIncrease
        case healthyHabits
        case looseWeight
        case relationshipsWithFood
    }

    public enum WeightLossFocus: Codable {
        case activity
        case healthyHabits
        case nutrition
        case other
    }

    @Attribute(.unique)
    public let id: String

    public let isPaid: Bool
    public let eating: Eating
    public let registrationSource: RegistrationSource
    public let nhe: NHE?
    public let firstName: String?
    public let lastName: String?
    public let gender: Gender?
    public let height: String?
    public let age: Int?
    public let weight: String?
    public let targetWeight: String?
    public let bmi: String?
    public let goal: Goal?
    public let units: Units?
    public let weightLossFocus: WeightLossFocus?
    @Relationship(deleteRule: .cascade)
    public var subscription: ProfileSubscriptionModel?

    public init(
        id: String,
        isPaid: Bool,
        eating: Eating,
        registrationSource: RegistrationSource,
        nhe: NHE?,
        firstName: String?,
        lastName: String?,
        gender: Gender?,
        height: String?,
        age: Int?,
        weight: String?,
        targetWeight: String?,
        bmi: String?,
        goal: Goal?,
        units: Units?,
        weightLossFocus: WeightLossFocus?,
        subscription: ProfileSubscriptionModel?
    ) {
        self.id = id
        self.isPaid = isPaid
        self.eating = eating
        self.registrationSource = registrationSource
        self.nhe = nhe
        self.firstName = firstName
        self.lastName = lastName
        self.gender = gender
        self.height = height
        self.age = age
        self.weight = weight
        self.targetWeight = targetWeight
        self.bmi = bmi
        self.goal = goal
        self.units = units
        self.weightLossFocus = weightLossFocus
        self.subscription = subscription
    }
}
@Model
public final class ProfileSubscriptionModel {

    public static let fetchDescriptor = FetchDescriptor<ProfileSubscriptionModel>.self

    public let price: Double
    public let currency: String
    public let period: Int
    public let status: String
    public let expirationDate: Date
    public let cancelledAt: Date?

    public init(price: Double, currency: String, period: Int, status: String, expirationDate: Date, cancelledAt: Date?) {
        self.price = price
        self.currency = currency
        self.period = period
        self.status = status
        self.expirationDate = expirationDate
        self.cancelledAt = cancelledAt
    }
}
SwiftData FatalError Unknown Relationship Key
 
 
Q