Uploaded image for project: 'Realm Kotlin'
  1. Realm Kotlin
  2. RKOTLIN-839

Crash in copyToRealm.

      How frequently does the bug occur?

      Sometimes

      Description

      I've got a weird crash when copyToRealm.

      open class PendingPhone : RealmObject {
      
            @PrimaryKey
            var pendingId: String = ""
            var client: Client? = null
            var dealtId: Long = 0
            var clientId: Long = 0
            var phoneType: PhoneType? = null
            var phoneColorType: PhoneColorType? = null
            var phoneOwnerType: PhoneOwnerType? = null
            var phoneNumber: String = ""
            var description: String? = null
            var creatingDate: Long = 0
            var syncDate: Long? = null
      }
      

      I am trying to save the given object in Realm:

        val creatingDate = Instant.now().toEpochMilli()
        val newPhone = PendingPhone().apply {
           this.pendingId = pendingId
           this.debtor = debtor
           this.debtId = debtId
           this.debtorId = debtor.debtorId
           this.phoneType = phoneType
           this.phoneColorType = null
           this.phoneOwnerType = phoneOwnerType
           this.phoneNumber = phoneNumber
           this.description = description
           this.creatingDate = creatingDate
           this.syncDate = null
        }
      
        realmTemplate.executeInRealm { realm ->
           realm.copyToRealm(newPhone)
        }
      
       suspend fun <T> executeInRealm(code: (MutableRealm) -> T): = realm.writeBlocking {
          code.invoke(this)
      }
      

      In this case, if you call findLatest before saving, as the error says, then after the error it will say that the object has not yet been created, use copyToRealm

      What am I doing wrong??

      Stacktrace & log output

      Unable to find source-code formatter for language: shell. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      Stacktrace below :
      
      java.lang.IllegalArgumentException: Cannot import an outdated object. Use findLatest(object) to find an up-to-date version of the object in the given context before importing it.
      

      Can you reproduce the bug?

      – select –

      Reproduction Steps

      No response

      Version

      1.8.0

      What Atlas App Services are you using?

      Local Database only

      Are you using encryption?

      Yes

      Platform OS and version(s)

      Android, v. 10

      Build environment

      Android Studio version: ...
      Android Build Tools version: ...
      Gradle version: ...

            Assignee:
            Unassigned Unassigned
            Reporter:
            unitosyncbot Unito Sync Bot
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: