Crash when adding indexes to Entity #361

Closed
opened 2025-12-29 15:30:03 +01:00 by adam · 0 comments
Owner

Originally created by @sergio-hurtado-forcemanager on GitHub (May 26, 2021).

[CoreStore: Assertion Failure] Field.Stored.swift:156 subscript(_enclosingInstance:wrapped:storage:)
↪︎ Attempted to access values from a 'ValueListGeneric' meta object. Meta objects are only used for querying keyPaths and infering types.

 var dbSchema = CoreStoreSchema(modelVersion: CDModels.latestModelVersion,
                                       entities: CDModels.latestEntitiesShema)
public enum CDModels  {
    
    typealias ValueListGeneric = CDModels.V1.ValueListGeneric
    
    static let latestEntitiesShema : [DynamicEntity] = [ValueListGeneric.schema()]
    static let latestModelVersion = CDModels.V1.name
}

then

extension CDModels.V1.ValueListGeneric {
    public static let schemaName: String = "ValueListGeneric"
    public static func schema() -> Entity<CDModels.V1.ValueListGeneric> {
        
        let indexOne: [PartialKeyPath<CDModels.V1.ValueListGeneric>] = [\CDModels.V1.ValueListGeneric.id, \CDModels.V1.ValueListGeneric.tableName]
        
        return Entity<CDModels.V1.ValueListGeneric>(self.schemaName,
                                        indexes: [indexOne],
                                        uniqueConstraints: [indexOne])
    }
}

its launching the assert from here

public init(_ type: O.Type, _ entityName: String, isAbstract: Bool = false, versionHashModifier: String? = nil, indexes: [[PartialKeyPath<O>]] = [], uniqueConstraints: [[PartialKeyPath<O>]]) {
        
        let meta = O.meta
        let toStringArray: ([PartialKeyPath<O>]) -> [KeyPathString] = {
            
            return $0.map {
                
                return (meta[keyPath: $0] as! AnyKeyPathStringConvertible).cs_keyPathString <--------- it's saying meta rawObject shouldn't be nil. But I'm just starting the datastack that isn't possible
            }
        }
        super.init(
            type: type,
            entityName: entityName,
            isAbstract: isAbstract,
            versionHashModifier: versionHashModifier,
            indexes: indexes.map(toStringArray),
            uniqueConstraints: uniqueConstraints.map(toStringArray)
        )
    }
Originally created by @sergio-hurtado-forcemanager on GitHub (May 26, 2021). ❗ [CoreStore: Assertion Failure] Field.Stored.swift:156 subscript(_enclosingInstance:wrapped:storage:) ↪︎ Attempted to access values from a 'ValueListGeneric' meta object. Meta objects are only used for querying keyPaths and infering types. ``` var dbSchema = CoreStoreSchema(modelVersion: CDModels.latestModelVersion, entities: CDModels.latestEntitiesShema) ``` ``` public enum CDModels { typealias ValueListGeneric = CDModels.V1.ValueListGeneric static let latestEntitiesShema : [DynamicEntity] = [ValueListGeneric.schema()] static let latestModelVersion = CDModels.V1.name } ``` then ``` extension CDModels.V1.ValueListGeneric { public static let schemaName: String = "ValueListGeneric" public static func schema() -> Entity<CDModels.V1.ValueListGeneric> { let indexOne: [PartialKeyPath<CDModels.V1.ValueListGeneric>] = [\CDModels.V1.ValueListGeneric.id, \CDModels.V1.ValueListGeneric.tableName] return Entity<CDModels.V1.ValueListGeneric>(self.schemaName, indexes: [indexOne], uniqueConstraints: [indexOne]) } } ``` its launching the assert from here ``` public init(_ type: O.Type, _ entityName: String, isAbstract: Bool = false, versionHashModifier: String? = nil, indexes: [[PartialKeyPath<O>]] = [], uniqueConstraints: [[PartialKeyPath<O>]]) { let meta = O.meta let toStringArray: ([PartialKeyPath<O>]) -> [KeyPathString] = { return $0.map { return (meta[keyPath: $0] as! AnyKeyPathStringConvertible).cs_keyPathString <--------- it's saying meta rawObject shouldn't be nil. But I'm just starting the datastack that isn't possible } } super.init( type: type, entityName: entityName, isAbstract: isAbstract, versionHashModifier: versionHashModifier, indexes: indexes.map(toStringArray), uniqueConstraints: uniqueConstraints.map(toStringArray) ) } ```
adam closed this issue 2025-12-29 15:30:03 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/CoreStore#361