Uploaded image for project: 'Realm Cocoa SDK'
  1. Realm Cocoa SDK
  2. RCOCOA-2269

Invalid column key RLMException

      How frequently does the bug occur?

      Once

      Description

      Sometimes, accessing the Results.count property results in an 'RLMException' with the message 'Invalid column key', leading to an application crash.
      > Terminating app due to uncaught exception 'RLMException', reason: 'Invalid column key'

      - (NSUInteger)count {
          return translateErrors([&] { return _results.size(); });
      }
      

      The app uses an Actor isolated Realm, which might be relevant to the issue.
      Maybe you know how to avoid or fix this?

      Code snippet

          private func fetchItemsList(projects: [Project]) async throws -> [ProjectItem] {
              return try await projects.asyncMap { [likeRepository] project in
                  let likesCount = try await likeRepository.fetch(byProjectID: project.id).count 
                  return ProjectItem(project: project, likesCount: likesCount)
              }
          }
      
      class LikeRepository: Repository {
      
          typealias Entity = Like
      
          func fetch(byProjectID id: String, ascending: Bool = false) async throws -> Results<Entity> {
              return try await RealmWrapper.database.objects(Entity.self)
                  .where { $0.projectId == id }
                  .sorted(by: \.createdAt, ascending: ascending)
          }
      }
      
      enum RealmWrapper {
         
          static var database: Realm {
              get async throws {
                  let configuration = RealmConfigurationManager.currentConfiguration
                  return try await Realm(configuration: configuration, actor: DatabaseActor.shared)
              }
          }
      }
      
      

      Stacktrace & log output

      No response

      Can you reproduce the bug?

      No

      Reproduction Steps

      No response

      Version

      10.45.2

      What Atlas Services are you using?

      Atlas Device Sync

      Are you using encryption?

      No

      Platform OS and version(s)

      iOS 16.7.2

      Build environment

      Xcode version: 14.3.1
      Dependency manager and version: Tuist - 3.28.0

            Assignee:
            nikola.irinchev@mongodb.com Nikola Irinchev
            Reporter:
            unitosyncbot Unito Sync Bot
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: