Parse-Swift
Parse-Swift copied to clipboard
Parse.User save not dispatching back to callback queue when result is success
New Issue Checklist
- [x] I am not disclosing a vulnerability.
- [x] I am not just asking a question.
- [x] I have searched through existing issues.
- [x] I can reproduce the issue with the latest versions of Parse Server and the Parse Swift SDK.
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
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?
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))
}
}
}
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
@mtrezza, who could check and eventually release the #448? I gave learned a bit more and hopefully figured it out. Thank you!