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

Mappable crashing in List<StringValue> #311

Closed
ifabijanovic opened this issue Jul 27, 2018 · 11 comments
Closed

Mappable crashing in List<StringValue> #311

ifabijanovic opened this issue Jul 27, 2018 · 11 comments

Comments

@ifabijanovic
Copy link
Contributor

ifabijanovic commented Jul 27, 2018

After updating to version 3.18.1 my models are crashing when trying to map List<StringValue> with exception:

Terminating app due to uncaught exception 'RLMException', reason: 'Invalid value 'XXXXX' to initialize object of type 'StringValue': missing key 'value''.

Model looks something like this:

class MyModel: Kinvey.Entity {
  @objc dynamic var someSimpleProperty: String?
  @objc dynamic var someComplexProperty: ComplexType?

  override func propertyMapping(_ map: Map) {
    super.propertyMapping(map)

    self.someSimpleProperty <- ("someSimpleProperty", map["someSimpleProperty"])
    self.someComplexProperty <- ("someComplexProperty", map["someComplexProperty"])
  }
}

class ComplexType: Kinvey.Object, Kinvey.Mappable {
  @objc dynamic var someSimpleProperty: String?
  let someListProperty = Kinvey.List<StringValue>()

  func mapping(map: Map) {
    self.someSimpleProperty <- ("someSimpleProperty", map["someSimpleProperty"])
    self.someListProperty <- ("someListProperty", map["someListProperty"])
  }
}

Tested on iPhone 8 simulator, iOS 11.4. Happens regardless if its a fresh app install or update from app running an older Kinvey SDK (and maybe performing a data migration). Xcode 9.4.1, macOs 10.13.6.

Shift to Codable is a really big change, is the SDK going to major version 4 soon when Mappable support is removed?

@ifabijanovic
Copy link
Contributor Author

After a bit more research this issue seems to manifest for List<DoubleValue> as well, but only when those properties are in a Kinvey.Object - not in Kinvey.Entity.

@heyzooi
Copy link
Contributor

heyzooi commented Jul 27, 2018

Hi @ifabijanovic, thanks for report this bug and i'm glad to say that we already have a fix for it and will be released in the next version.

Until we release the new version you can test using the feature/MLIBZ-2635-codable_support_for_list branch.

The PR in under review right now.

@ifabijanovic
Copy link
Contributor Author

Hello, I've tested with 3.18.2 and issue is still present

@heyzooi
Copy link
Contributor

heyzooi commented Aug 2, 2018

@ifabijanovic are you getting the same issue using 3.18.2 or is a different issue?

@heyzooi
Copy link
Contributor

heyzooi commented Aug 2, 2018

btw, your code should be

let someListProperty = Kinvey.List<StringValue>()

@ifabijanovic
Copy link
Contributor Author

Yeah sorry, I did initialize the list property (updated snippet) otherwise it wouldn't compile.

I am getting the same issue - Terminating app due to uncaught exception 'RLMException', reason: 'Invalid value 'XXXXX' to initialize object of type 'StringValue': missing key 'value''. I have not updated my models yet to use Swift.Codable - still using Kinvey.Mappable. If I comment out just self.someListProperty <- ("someListProperty", map["someListProperty"]) it still crashes, only after completely removing the someListProperty property completely does it go away.

Strangely I have other models with similar structure (List in Kinvey.Object), but in Kinvey.Entity I have a List instead of a 1-to-1 relation and it does not crash there. So something like:

class MyModel: Kinvey.Entity {
  @objc dynamic var someSimpleProperty: String?
  let someComplexPropertyList = Kinvey.List<ComplexType>()

  override func propertyMapping(_ map: Map) {
    super.propertyMapping(map)

    self.someSimpleProperty <- ("someSimpleProperty", map["someSimpleProperty"])
    self.someComplexPropertyList <- ("someComplexPropertyList", map["someComplexPropertyList"])
  }
}

class ComplexType: Kinvey.Object, Kinvey.Mappable {
  @objc dynamic var someSimpleProperty: String?
  let someListProperty = Kinvey.List<StringValue>()

  func mapping(map: Map) {
    self.someSimpleProperty <- ("someSimpleProperty", map["someSimpleProperty"])
    self.someListProperty <- ("someListProperty", map["someListProperty"])
  }
}

I tried migrating this model to Swift.Codable to see if that resolves the issue, but I cannot decode List<StringValue> - I think StringValue needs to implement the Decodable protocol. This applies to DoubleValue and others as well I guess.

@heyzooi
Copy link
Contributor

heyzooi commented Aug 3, 2018

@ifabijanovic could you confirm the Realm version that you are using?

@ifabijanovic
Copy link
Contributor Author

realm-cocoa v3.7.5, I use Carthage for dependency management.

@heyzooi
Copy link
Contributor

heyzooi commented Aug 13, 2018

I believe this PR #314 can fix your problem. Let me know if you are able to test against this branch, otherwise it will be available in the next release.

@ifabijanovic
Copy link
Contributor Author

Hello, I've tested on branch feature/MLIBZ-2646-support_for_list_of_primitive_values and the issue is still present when using Mappable. After refactoring the problematic entity to use Codable instead, issue disappears and everything loads correctly.

From my point of view, this issue is resolved. You do however have a backwards compatibility issue here.

@ifabijanovic
Copy link
Contributor Author

While testing the above branch I ran into an issue when trying to implement Codable in custom user class (one inheriting from Kinvey.User) - I am unable to override encode(to encoder: Encoder) throws since it is marked as public - it should be open

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants