realm / realm-core

Core database component for the Realm Mobile Database SDKs
https://realm.io
Apache License 2.0
1.02k stars 164 forks source link

Assertion failed: get_real_column_type(col_ndx) == col_type_Bool [13, 1] #1861

Closed stel closed 8 years ago

stel commented 8 years ago

Cocoa user reported this on Help Scout: https://secure.helpscout.net/conversation/210617274/4683

2016-06-03 15:31:59.202 [Error] > Attempt to open log file for writing failed: The operation couldn't be completed. (Cocoa error 2.)
table.cpp:2890: [realm-core-0.100.4] Assertion failed: get_real_column_type(col_ndx) == col_type_Bool [13, 1]
0 Realm 0x00000001041defd8 _ZN5realm4util18terminate_internalERNSt3__118basic_stringstreamIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE + 40
1 Realm 0x0000000104310820 _ZN5realm4util9terminateIJNS_10ColumnTypeES2_EEEvPKcS4_lDpT_ + 544
2 Realm 0x000000010434f9cc _ZN5realm5Table8set_boolEmmb + 940
3 Realm 0x000000010403cb65 _ZN5realm8RowFuncsINS_5TableENS_8BasicRowIS1_EEE8set_boolEmb + 85
4 Realm 0x0000000104037522 _ZL11RLMSetValueP13RLMObjectBasemb + 66
5 Realm 0x000000010403b581 _ZZ13RLMDynamicSetENK3$_0clEv + 785
6 Realm 0x0000000104031107 _ZL13RLMWrapSetterIZ13RLMDynamicSetE3$_0EvP13RLMObjectBaseP8NSStringOT_ + 183
7 Realm 0x0000000104030eea RLMDynamicSet + 154
8 Realm 0x0000000104030d7f RLMDynamicValidatedSet + 959
9 RealmSwift 0x00000001046cb3e2 _TFC10RealmSwift6Objects9subscriptFSSGSqPs9AnyObject__ + 338
10 MUMO 0x000000010108bbef _TFFFC4MUMO11AppDelegate11applicationFTCSo13UIApplication29didFinishLaunchingWithOptionsGSqGVs10DictionaryCSo8NSObjectPs9AnyObject____SbU_FTC10RealmSwift9MigrationVs6UInt64_T_U_FTGSqCS5_13DynamicObject_GSqS8___T_ + 991
11 RealmSwift 0x00000001046c9a55 _TFFC10RealmSwift9Migration9enumerateFTSSFT9oldObjectGSqCS_13DynamicObject_9newObjectGSqS1___T__T_U_FTGSqCSo9RLMObject_GSqS2___T_ + 277
12 RealmSwift 0x00000001046c9ad1 _TTRXFo_oGSqCSo9RLMObject_oGSqS___dT__XFdCb_dGSqS__dGSqS___dT__ + 81
13 Realm 0x000000010405421c -[RLMMigration enumerateObjects:block:] + 1004
14 RealmSwift 0x00000001046c8f06 _TFC10RealmSwift9Migration9enumeratefTSSFT9oldObjectGSqCS_13DynamicObject_9newObjectGSqS1___T__T_ + 326
15 MUMO 0x000000010108b4c9 _TFFC4MUMO11AppDelegate11applicationFTCSo13UIApplication29didFinishLaunchingWithOptionsGSqGVs10DictionaryCSo8NSObjectPs9AnyObject____SbU_FTC10RealmSwift9MigrationVs6UInt64_T_ + 233
16 MUMO 0x000000010108db23 _TTRXFo_oC10RealmSwift9MigrationdVs6UInt64_dT__XFo_iT9migrationS0_16oldSchemaVersionS1___iT__ + 35
17 MUMO 0x00000001010869b1 _TPA__TTRXFo_oC10RealmSwift9MigrationdVs6UInt64_dT__XFo_iT9migrationS0_16oldSchemaVersionS1___iT__ + 81
18 RealmSwift 0x00000001046e8bf7 _TTRXFo_iT9migrationC10RealmSwift9Migration16oldSchemaVersionVs6UInt64__iT__XFo_oS0_dS1__dT__ + 39
19 RealmSwift 0x00000001046ca0d5 _TFF10RealmSwift22accessorMigrationBlockFFT9migrationCS_9Migration16oldSchemaVersionVs6UInt64_T_FTCSo12RLMMigrationS1__T_U_FTS2_S1__T_ + 1525
20 RealmSwift 0x00000001046e8c23 _TTRXFo_oCSo12RLMMigrationdVs6UInt64_dT__XFo_iTS_S0___iT__ + 35
21 RealmSwift 0x00000001046e8111 _TPA__TTRXFo_oCSo12RLMMigrationdVs6UInt64_dT__XFo_iTS_S0___iT__.28 + 81
22 RealmSwift 0x00000001046e8c57 _TTRXFo_iTCSo12RLMMigrationVs6UInt64__iT__XFo_oS_dS0__dT__ + 39
23 RealmSwift 0x00000001046e8ca4 _TTRXFo_oCSo12RLMMigrationdVs6UInt64_dT__XFdCb_dS_dS0__dT__ + 68
24 Realm 0x00000001040549c2 -[RLMMigration execute:] + 850
25 Realm 0x0000000104181475 _ZZ41+[RLMRealm realmWithConfiguration:error:]ENK3$_0clENSt3__110shared_ptrIN5realm5RealmEEES4_ + 965
26 Realm 0x000000010418104f _ZNSt3__128__invoke_void_return_wrapperIvE6__callIJRZ41+[RLMRealm realmWithConfiguration:error:]E3$_0NS_10shared_ptrIN5realm5RealmEEES8_EEEvDpOT_ + 287
27 Realm 0x0000000104180d79 _ZNSt3__110__function6__funcIZ41+[RLMRealm realmWithConfiguration:error:]E3$_0NS_9allocatorIS2_EEFvNS_10shared_ptrIN5realm5RealmEEES8_EEclEOS8_SB_ + 73
28 Realm 0x00000001041b203c _ZNKSt3__18functionIFvNS_10shared_ptrIN5realm5RealmEEES4_EEclES4_S4_ + 172
29 Realm 0x00000001041aeb0c _ZZN5realm5Realm13update_schemaENSt3__110unique_ptrINS_6SchemaENS1_14default_deleteIS3_EEEEyENK3$_0clEPNS_5GroupERS3_ + 508
30 Realm 0x00000001041ae900 _ZNSt3__128__invoke_void_return_wrapperIvE6__callIJRZN5realm5Realm13update_schemaENS_10unique_ptrINS3_6SchemaENS_14default_deleteIS6_EEEEyE3$_0PNS3_5GroupERS6_EEEvDpOT_ + 112
31 Realm 0x00000001041ae7d9 _ZNSt3__110__function6__funcIZN5realm5Realm13update_schemaENS_10unique_ptrINS2_6SchemaENS_14default_deleteIS5_EEEEyE3$_0NS_9allocatorIS9_EEFvPNS2_5GroupERS5_EEclEOSD_SE_ + 73
32 Realm 0x0000000103fe8b54 _ZNKSt3__18functionIFvPN5realm5GroupERNS1_6SchemaEEEclES3_S5_ + 180
33 Realm 0x0000000103fd341c _ZN5realm11ObjectStore24update_realm_with_schemaEPNS_5GroupERKNS_6SchemaEyRS3_NSt3__18functionIFvS2_S6_EEE + 316
34 Realm 0x00000001041aa4bb _ZN5realm5Realm13update_schemaENSt3__110unique_ptrINS_6SchemaENS1_14default_deleteIS3_EEEEy + 1835
35 Realm 0x000000010417a3a6 +[RLMRealm realmWithConfiguration:error:] + 7638
36 RealmSwift 0x00000001046d986c _TTOFCSo8RLMRealmCfzT13configurationCSo21RLMRealmConfiguration_S_ + 92
37 RealmSwift 0x00000001046d63ae _TFC10RealmSwift5RealmcfzT_S0_ + 110
38 RealmSwift 0x00000001046d6476 _TFC10RealmSwift5RealmCfzT_S0_ + 54
39 MUMO 0x0000000101072747 _TFC4MUMO11AppDelegate11applicationfTCSo13UIApplication29didFinishLaunchingWithOptionsGSqGVs10DictionaryCSo8NSObjectPs9AnyObject____Sb + 1655
40 MUMO 0x0000000101073664 _TToFC4MUMO11AppDelegate11applicationfTCSo13UIApplication29didFinishLaunchingWithOptionsGSqGVs10DictionaryCSo8NSObjectPs9AnyObject____Sb + 180
41 UIKit 0x00000001051269ac -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 272
42 UIKit 0x0000000105127c0d -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 3415
43 UIKit 0x000000010512e568 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1769
44 UIKit 0x000000010512b714 -[UIApplication workspaceDidEndTransaction:] + 188
45 FrontBoardServices 0x000000010a1c78c8 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 24
46 FrontBoardServices 0x000000010a1c7741 -[FBSSerialQueue _performNext] + 178
47 FrontBoardServices 0x000000010a1c7aca -[FBSSerialQueue _performNextFromRunLoopSource] + 45
48 CoreFoundation 0x0000000107954301 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
49 CoreFoundation 0x000000010794a22c __CFRunLoopDoSources0 + 556
50 CoreFoundation 0x00000001079496e3 __CFRunLoopRun + 867
51 CoreFoundation 0x00000001079490f8 CFRunLoopRunSpecific + 488
52 UIKit 0x000000010512af21 -[UIApplication _run] + 402
53 UIKit 0x000000010512ff09 UIApplicationMain + 171
54 MUMO 0x00000001010885a2 main + 114
55 libdyld.dylib 0x0000000108a8992d start + 1`
ironage commented 8 years ago

The trace shows that somehow the user is calling set_bool on a column which is actually of type col_type_LinkList (13) in the middle of a migration. Assuming the object store is updating column indices correctly during a migration then this is either a bug or corruption somewhere from core. Really difficult to progress without more info about how to reproduce this so I am going to mark as waiting for user.

ironage commented 8 years ago

If the user is willing to provide any more information, it would be interesting to see the user's model before and after the migration and the migration code. Maybe there is some combination of structural changes in the migration that could cause this.

stel commented 8 years ago

User replied:

Before migration

class Follower: Object {
    dynamic var id = ""
    dynamic var mainUserID = ""
    dynamic var username = ""
    dynamic var strProfileURL = ""
    dynamic var isFollowingMe = false

    override class func primaryKey() -> String {
        return "id"
    }
}

class Following: Object {
    dynamic var id = ""
    dynamic var mainUserID = ""
    dynamic var username = ""
    dynamic var strProfileURL = ""

    override class func primaryKey() -> String {
        return "id"
    }
}

class User: Object {
    dynamic var id = ""
    dynamic var username = ""
    dynamic var email = ""
    dynamic var fullName = ""
    dynamic var token = ""
    dynamic var strURLImageProfile = ""
    dynamic var phoneNumber = ""
    dynamic var bio = ""
    dynamic var lastMomentCaptionImageURL = ""
    dynamic var totalListners = 0
    dynamic var totalMoments = 0
    dynamic var totalFollowers = 0
    dynamic var totalFollowings = 0
    dynamic var totalWhispers = 0
    dynamic var totalLovedWhispers = 0
    dynamic var totalPartiedWhispers = 0
    dynamic var totalChilledWhispers = 0
    dynamic var isFacebookConnected = false
    dynamic var isTwitterConnected = false
    // dynamic var type = UserType.Normal.hashValue // added to check user is me, of featured user or some other user
    dynamic var isFollowing = false // added to check featured user is being followed by me of not
    dynamic var index = 0
    internal let toAccount = List<Account>()

    internal var toUser: User {
        return linkingObjects(User.self, forProperty: "featureUser").first!
    }

    internal let featureUser = List<User>()

    override class func primaryKey() -> String {
        return "id"
    }
}

class Moment: Object {
    dynamic var id = ""
    dynamic var visibility = ""
    dynamic var isActive = false
    dynamic var captionImageUrl = ""
    dynamic var playlistID = ""
    dynamic var userID = ""
    dynamic var userImageUrl = ""
    dynamic var userFullName = ""
    dynamic var userUsername = ""
    dynamic var captionMessage = ""
    dynamic var createdTime = NSDate()
    dynamic var noOfWhispers = 0
    dynamic var noOfListeners = 0
    dynamic var noOfMaxListeners = 0
    dynamic var noOfWebListeners = 0
    dynamic var hasReported = false
    dynamic var hasReportedBy3 = false

    override class func primaryKey() -> String {
        return "id"
    }
}

class Playlist: Object {
    dynamic var name = ""
    //dynamic var songs = RLMArray(objectClassName: Song.className())
}

class Song: Object {
    dynamic var id = ""
    dynamic var name = ""
    dynamic var albumImageURL = ""
    dynamic var albumName = ""
    dynamic var artistImageURL = ""
    dynamic var artistName = ""
    dynamic var order = 0
    dynamic var mnetID = 0
    dynamic var locationURL = ""
    dynamic var locationURL_mp4 = ""
    dynamic var iTunesURL = ""

    override class func primaryKey() -> String {
        return "id"
    }
}

class Account: Object {
    dynamic var id = ""
    dynamic var type = AccountType.Mumo.rawValue
    dynamic var accessToken = ""
    dynamic var accessSecret = ""
    dynamic var userID = ""
    dynamic var isMainAccount = false

    internal var toUser: User {
        return linkingObjects(User.self, forProperty: "toAccount").first!
    }

    override class func primaryKey() -> String {
        return "id"
    }

    // Specify properties to ignore (Realm won't persist these)

    // override static func ignoredProperties() -> [String] {
    // return []
    // }
}

AFTER MIGRATION

class User: Object {
    dynamic var id = ""
    dynamic var username = ""
    dynamic var email = ""
    dynamic var fullName = ""
    dynamic var token = ""
    dynamic var profileImageURL = ""
    dynamic var phoneNumber = ""
    dynamic var bio = ""
    dynamic var lastMomentCaptionImageURL = ""
    dynamic var totalListners = 0
    dynamic var totalMoments = 0
    dynamic var totalFollowers = 0
    dynamic var totalFollowings = 0
    dynamic var totalWhispers = 0
    dynamic var totalLovedWhispers = 0
    dynamic var totalPartiedWhispers = 0
    dynamic var totalChilledWhispers = 0
    dynamic var isFollowingUser = false
    dynamic var blocked = false
    dynamic var isFacebookConnected = false
    dynamic var isTwitterConnected = false

    //TODO: remove this
    internal let toAccount = List<Account>()

    var followers = List<User>()
    var following = List<User>()
    var suggestedUsers = List<User>()
    var whispers = List<Song>()

    override class func primaryKey() -> String {
        return "id"
    }
}

class Session: Object {
    dynamic var id = ""
    dynamic var token = ""
    dynamic var isFacebookConnected = false
    dynamic var isTwitterConnected = false
    dynamic var twitterLogin = false
    dynamic var currentUser: User?

    override static func primaryKey() -> String? {
        return "id"
    }
}

class Moment: Object {
    dynamic var id = ""
    dynamic var visibility = ""
    dynamic var isActive = false
    dynamic var captionImageUrl = ""
    dynamic var playlistID = ""
    dynamic var captionMessage = ""
    dynamic var createdTime = NSDate()
    dynamic var noOfWhispers = 0
    dynamic var noOfListeners = 0
    dynamic var noOfMaxListeners = 0
    dynamic var noOfWebListeners = 0
    dynamic var hasReported = false
    dynamic var hasReportedBy3 = false
    dynamic var commentsCount = 0
    dynamic var user: User?

    var songs = List<Song>()
    var whispers = List<Whisper>()
    var comments = List<Comment>()
    var listeners = List<User>()

    override class func primaryKey() -> String {
        return "id"
    }
}

class Song: Object {
    dynamic var id = ""
    dynamic var name = ""
    dynamic var albumImageURL = ""
    dynamic var albumName = ""
    dynamic var artistImageURL = ""
    dynamic var artistName = ""
    dynamic var order = 0
    dynamic var mnetID = 0
    dynamic var locationURL = ""
    dynamic var locationURL_mp4 = ""
    dynamic var iTunesURL = ""
    dynamic var songURL = ""
    dynamic var durationInMS = 0
    dynamic var startAt: Double = 0
    dynamic var duration = 0

    override class func primaryKey() -> String {
        return "id"
    }
}

class Whisper: Object {
    dynamic var id = ""
    dynamic var type: String = ""
    dynamic var label: String = ""
    dynamic var createdTime = NSDate()
    dynamic var user: User?
    dynamic var song: Song?

    override class func primaryKey() -> String {
        return "id"
    }
}

class Comment: Object {
    dynamic var id = ""
    dynamic var caption: String = ""
    dynamic var user: User?
    dynamic var createdTime = NSDate()

    override class func primaryKey() -> String {
        return "id"
    }
}

MIGRATION BLOCK WRITTEN

Realm.Configuration.defaultConfiguration = Realm.Configuration(
    schemaVersion: 7,
    migrationBlock: { migration, oldSchemaVersion in

        migration.enumerate(User.className()) { oldObject, newObject in

            if oldSchemaVersion == 4 {

                // migration.deleteData(User.className())

                if let object1 = newObject {
                    migration.renamePropertyForClass(User.className(), oldName: "isFollowing", newName: "isFollowingUser")
                    migration.renamePropertyForClass(User.className(), oldName: "strURLImageProfile", newName: "profileImageURL")

                    // object1["isFollowingUser"] = object["isFollowing"]
                    // object1["profileImageURL"] = object["strURLImageProfile"]
                    object1["blocked"] = false
                    object1["followers"] = []
                    object1["following"] = []
                    object1["suggestedUsers"] = []
                    object1["whispers"] = []

                }

            }
            if oldSchemaVersion == 4 {
                if let object = oldObject {
                    if let oldToken = object["token"] as? String {

                        if oldToken != "" {
                            if let oldUserID = object["id"] {
                                //TODO: call api passing token and userid

                                Session.addOldOne(["_id":oldUserID, "token":oldToken])

                                //TODO: check following api. gettting "Please login in order to use this resource."
                                //i think access token is not valid in this new environment
                                store.dispatch(actionGetUser(oldUserID as! String, disposeBag: self.disposeBag))

                            }
                        }
                    }
                }

            }

        }
        // The enumerateObjects:block: method iterates
        // over every 'Moment' object stored in the Realm file
        migration.enumerate(Moment.className()) { oldObject, newObject in
            if oldSchemaVersion == 4{
                // migration.deleteData(Moment.className())

                if let object = oldObject, let object1 = newObject {
                    if let momentOwnerId = object["userID"] as? String {
                        let user = User.findOne(momentOwnerId)
                        object1["user"] = user
                    }

                    object1["commentsCount"] = 0
                    object1["songs"] = []
                    object1["comments"] = []
                    object1["whispers"] = []
                    object1["listeners"] = 0
                }
            }
        }
        migration.enumerate(Session.className()) { oldObject, newObject in

            if oldSchemaVersion < 6 {
                newObject!["twitterLogin"] = false;
            }

        }

        migration.enumerate(Song.className()) { oldObject, newObject in
            // Add the `durationInMS` 'startAt' property to Realms with a schema version of 2 or 2

            if oldSchemaVersion < 2 {
                newObject!["durationInMS"] = 0
                newObject!["startAt"] = 0
            }

            if oldSchemaVersion < 3 {
                newObject!["startAt"] = oldObject!["startAt"]
            }

            if oldSchemaVersion == 4 {
                if let object = oldObject, let object1 = newObject {
                    object1["songURL"] = ""
                    object1["durationInMS"] = 0
                    object1["startAt"] = 0
                    object1["duration"] = 0
                }

            }
        }

        migration.enumerate(Whisper.className()) { oldObject, newObject in
            if oldSchemaVersion < 6 {
                newObject!["song"] = Song();
            }
        }

})
stel commented 8 years ago

object1["listeners"] = 0 may cause this error, as Moment.listeners is List<User>().

ironage commented 8 years ago

@stel The error you pointed out is the user's mistake, and could explain the stack trace. Can we close this issue?

stel commented 8 years ago

User didn't respond to my previous message, I'll ask him again. Anyway it's definitely the user's error, so yeah, will close this issue.