Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RLMException', reason: 'Invalid value for property' #5364

Closed
ralfcheung opened this issue Oct 3, 2017 · 6 comments
Closed

RLMException', reason: 'Invalid value for property' #5364

ralfcheung opened this issue Oct 3, 2017 · 6 comments
Labels

Comments

@ralfcheung
Copy link

ralfcheung commented Oct 3, 2017

Expected Results

Write the object without error/crash

## Actual Results
* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
    frame #0: 0x00000001867e9348 libsystem_kernel.dylib`__pthread_kill + 8
    frame #1: 0x00000001868fd354 libsystem_pthread.dylib`pthread_kill$VARIANT$mp + 396
    frame #2: 0x0000000186758fd8 libsystem_c.dylib`abort + 140
    frame #3: 0x00000001861bc068 libc++abi.dylib`abort_message + 132
    frame #4: 0x00000001861bc210 libc++abi.dylib`default_terminate_handler() + 304
    frame #5: 0x00000001861e4810 libobjc.A.dylib`_objc_terminate() + 124
    frame #6: 0x00000001861d454c libc++abi.dylib`std::__terminate(void (*)()) + 16
    frame #7: 0x00000001861d3ea8 libc++abi.dylib`__cxa_throw + 136
    frame #8: 0x00000001861e465c libobjc.A.dylib`objc_exception_throw + 364
  * frame #9: 0x0000000103858374 Realm`validateValueForProperty(obj="3", prop=0x00000001c40b5840, info=0x00000001c42d6438) at RLMAccessor.mm:604
    frame #10: 0x000000010385a2ec Realm`RLMAccessorContext::value_for_property(this=0x000000016d811c58, obj=0x000000014fe90890, (null)="pac", propIndex=6) at RLMAccessor.mm:834
    frame #11: 0x00000001038a3f44 Realm`realm::Object realm::Object::create<objc_object* __strong, RLMAccessorContext>(ctx=0x000000016d811c58, realm=std::__1::shared_ptr<realm::Realm>::element_type @ 0x000000014fd27458 strong=8 weak=5, object_schema=0x000000014fd7ca70, value=0x000000014fe90890, try_update=false, out_row=0x000000014fe90898) at object_accessor.hpp:268
    frame #12: 0x00000001038a32e0 Realm`::RLMAddObjectToRealm(object=0x000000014fe90890, realm=0x00000001c00b9200, createOrUpdate=false) at RLMObjectStore.mm:132
    frame #13: 0x000000010420e488 RealmSwift`Realm.add(object=0x000000014fe90890, update=false, self=0x00000001c0221740) at Realm.swift:287
    frame #14: 0x00000001027571f4 LinkaIOS`closure #3 in static Linka.saveLinka(linka=0x000000014fe90890, realm=0x00000001c0221740) at Linka.swift:472
    frame #15: 0x000000010420dd94 RealmSwift`Realm.write(block=0x0000000102757254 LinkaIOS`partial apply forwarder for closure #3 () -> () in static LinkaIOS.Linka.saveLinka(Swift.String, lock_mac_address: Swift.String, lock_name: Swift.String, allow_override: Swift.Bool) -> Swift.Bool at Linka.swift, self=0x00000001c0221740) at Realm.swift:155
    frame #16: 0x0000000102756b98 LinkaIOS`static Linka.saveLinka(lock_address="EBCACAF1-1E9C-9FFA-639C-44289E304C0B", lock_mac_address="E3:3A:78:42:62:E8", lock_name="LINKA 1", allow_override=true, self=LinkaIOS.Linka) at Linka.swift:473
    frame #17: 0x0000000102756450 LinkaIOS`static Linka.saveLinka(peripheral=0x00000001c48478f0, allow_override=true, self=LinkaIOS.Linka) at Linka.swift:439
    frame #18: 0x00000001027edfa8 LinkaIOS`closure #1 in closure #1 in SetupSearchLinkaViewController.tryPairup(self=0x000000014fe5e570, error=nil, p=0x00000001c48478f0) at SetupSearchLinkaViewController.swift:244
    frame #19: 0x00000001025f8780 LinkaIOS`thunk for @callee_owned () -> () at RevocationControllerV2.swift:0
    frame #20: 0x00000001051c149c libdispatch.dylib`_dispatch_call_block_and_release + 24
    frame #21: 0x00000001051c145c libdispatch.dylib`_dispatch_client_callout + 16
    frame #22: 0x00000001051c6050 libdispatch.dylib`_dispatch_main_queue_callback_4CF + 1192
    frame #23: 0x0000000186c77f20 CoreFoundation`__CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12
    frame #24: 0x0000000186c75afc CoreFoundation`__CFRunLoopRun + 2012
    frame #25: 0x0000000186b962d8 CoreFoundation`CFRunLoopRunSpecific + 436
    frame #26: 0x0000000188a27f84 GraphicsServices`GSEventRunModal + 100
    frame #27: 0x0000000190142880 UIKit`UIApplicationMain + 208
    frame #28: 0x00000001026f7700 LinkaIOS`main at AppDelegate.swift:21
    frame #29: 0x00000001866ba56c libdyld.dylib`start + 4

Steps to Reproduce

call Linka.saveLinka("123", lock_mac_address: "ad", lock_name: "asdfsdf", allow_override: true)

## Code Sample
open class Linka: Object, UIAlertViewDelegate {
    @objc dynamic var _id = 0
    @objc dynamic var lock_address : String = ""
    @objc dynamic var lock_mac_address : String = ""
    @objc dynamic var lock_name : String = ""
    @objc dynamic var isConnected : Bool = false
    @objc dynamic var isLocked : Bool = false
    @objc dynamic var isLocking : Bool = false
    @objc dynamic var isUnlocking : Bool = false
    @objc dynamic var isCharging : Bool = false
    @objc dynamic var pac : Int = 0
    @objc dynamic var batteryPercent : Int = 100
    @objc dynamic var origBatteryPercent : Int = 100
    @objc dynamic var lastChargingPercent : Int = 100
    @objc dynamic var lastUnpluggedPercent : Int = 0
}

    class func saveLinka(_ lock_address : String, lock_mac_address : String, lock_name : String, allow_override : Bool) -> Bool {
        let realm = try! Realm()
        
        let userID = Helpers.getUserID()
        
        let linkas = realm.objects(Linka.self).filter("lock_address == %@ AND api_user_id == %@", lock_address, userID)

        if linkas.count > 0 {
            if allow_override {
                let linka = linkas[0]
                
                try! realm.write {
                    realm.add(linka, update: true)
                }
                
                return true
            }
            return false
        }
        
        let linka = makeLinka(lock_address, lock_mac_address: lock_mac_address, lock_name: lock_name, peripheral: nil)

        let _id = realm.objects(Linka.self).map{$0._id}.max() ?? 0
        linka._id = _id + 1
        
        do {
            try realm.write {
                linka.pac = 3
                realm.add(linka)
            }
        } catch let e {
            print(e.localizedDescription)
        }

        return true
    }

Version of Realm and Tooling

ProductName: Mac OS X
ProductVersion: 10.13
BuildVersion: 17A362a

/Applications/Xcode 9.app/Contents/Developer
Xcode 9.0
Build version 9A235

/usr/local/bin/pod
1.3.1
Realm (2.10.1)
RealmSwift (2.10.1)

/bin/bash
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin17)

(not in use here)

/usr/bin/git
git version 2.13.5 (Apple Git-94)

Realm framework version: 2.10.1

Xcode version: 9

iOS/OSX version: 11.0

Swift version: 4

Dependency manager + version: Cocoapods 1.3.1

@kishikawakatsumi
Copy link
Contributor

@ralfcheung Generally, RLMException means wrong API usage error. According to the error message, pac seems to be passed" 3 "of the string type despite it is Int type.

Some method and property definitions are missing in your code snippet, such as Helpers.getUserID (), linka.peripheral and makeLinka (). Furthermore, the query filter (" lock_address ==% @ AND api_user_id ==% @ ", lock_address, userID) cannot be executed because it has also a missing property api_user_id. As a result, we could not compile and execute correctly, so we do not know anything further.

Could you please provide executable code that can reproduce the problem? With that, we can give you the right answer.

@ralfcheung
Copy link
Author

ralfcheung commented Oct 3, 2017

even if I strip down to the bare minimum. it still crashes.

`

override func setUp() {
    super.setUp()
    // Check Realm version
    var config = Realm.Configuration.defaultConfiguration
    config.schemaVersion = 20
    config.migrationBlock = { migration, oldSchemaVersion in
        if oldSchemaVersion < 20 {
        }
    }
    Realm.Configuration.defaultConfiguration = config
    
    realm = try! Realm()

}

func testMakeLinka() {

    let linka = Linka()
    
    do {
        try realm.write {
            realm.add(linka)
        }
    } catch let e {
        print(e.localizedDescription)
    }

}

`

the initial value of pac is 0 (in integer), I forced pac = 3 just to show I didn't accidentally set the value to string or other incorrect types, I even tried explicitly set pac = Int(3) and it also crashes

@kishikawakatsumi
Copy link
Contributor

@ralfcheung Please share an entire executable project that reproduces the issue. You can send it to help@realm.io. It may have crashed in your environment, but we do not know. This crash doesn't seem a Realm bug, it is considered a problem of your program, so without our accurate information, we can not help you.

@bdash
Copy link
Contributor

bdash commented Oct 3, 2017

Do you have any functions declared on your Linka type named anything like getPac or similar?

@ralfcheung
Copy link
Author

ralfcheung commented Oct 4, 2017

you know what, there is, and it returns a String for whatever reasons. and that worked in swift 3

@bdash
Copy link
Contributor

bdash commented Oct 4, 2017

When Realm uses Key-Value Coding to retrieve the value of the pac property, KVC follows a search pattern that includes looking for appropriate named getters. It tries getFoo before foo, which results in a getPac() function being called and the string it returns being used in the attempt to initialize the pac property.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants