Parse-Swift icon indicating copy to clipboard operation
Parse-Swift copied to clipboard

Parse.User save not dispatching back to callback queue when result is success

Open Aziz-AnyDesk opened this issue 3 years ago • 5 comments
trafficstars

New Issue Checklist

Issue Description

Parse.User save method is not dispatching the result back to callback queue if the result is success. It is dispatching back to callback queue only if it fails. Looking at source code, I suspect this might be the case for all Parse Objects.

Steps to reproduce

Call save method of existing Parse.User

Actual Outcome

The result is not dispatched back to the callback queue when the save succeeds.

Expected Outcome

The result should be dispatched back to the callback queue when save succeeds.

Environment

Plain iOS app with Parse client version 4.14.2.

Client

  • Parse Swift SDK version: 4.14.2
  • Xcode version: 14.1
  • Operating system (iOS, macOS, watchOS, etc.): macOS Ventura
  • Operating system version: Ventura 13.0.1

Aziz-AnyDesk avatar Nov 17 '22 10:11 Aziz-AnyDesk

Thanks for opening this issue!

  • 🚀 You can help us to fix this issue faster by opening a pull request with a failing test. See our Contribution Guide for how to make a pull request, or read our New Contributor's Guide if this is your first time contributing.

Thanks for reporting, could you provide a code example?

mtrezza avatar Nov 17 '22 17:11 mtrezza

Here is an example:

let currentUser = Parse.User.current
let userToUpdate = user.set(\.customKey, to: 5)
userToUpdate.save { result in
       print(Thread.isMainThread) 
       // This prints false even though save is called from main thread and default callback queue is set to main thread.
}

I believe this piece of code inside save function of ParseSwift SDK is responsible for this issue:

Task {
            do {
                let object = try await command(method: method,
                                               ignoringCustomObjectIdConfig: ignoringCustomObjectIdConfig,
                                               options: options,
                                               callbackQueue: callbackQueue)
                completion(.success(object)) // This is wrong. This line should be wrapped inside callbackQueue.async
            } catch {
                let defaultError = ParseError(code: .unknownError,
                                              message: error.localizedDescription)
                let parseError = error as? ParseError ?? defaultError
                callbackQueue.async {
                    completion(.failure(parseError))
                }
            }
        }

Aziz-AnyDesk avatar Nov 18 '22 11:11 Aziz-AnyDesk

I can confirm that this affects all ParseObjects. @mtrezza , I created Pull Request, could you please have a look at it? https://github.com/parse-community/Parse-Swift/pull/448

lsmilek1 avatar Nov 26 '23 12:11 lsmilek1

@mtrezza, who could check and eventually release the #448? I gave learned a bit more and hopefully figured it out. Thank you!

lsmilek1 avatar Feb 13 '24 18:02 lsmilek1