Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Ensuring initialize has returned before attempting queries. #169

Closed
cbaker6 opened this issue Mar 29, 2024 Discussed in #167 · 1 comment · Fixed by #168 or #193
Closed

Ensuring initialize has returned before attempting queries. #169

cbaker6 opened this issue Mar 29, 2024 Discussed in #167 · 1 comment · Fixed by #168 or #193
Labels
bug Something isn't working

Comments

@cbaker6
Copy link
Member

cbaker6 commented Mar 29, 2024

Discussed in #167

Originally posted by project-saf March 28, 2024
Very infrequently, I run in to a crash along the lines of:

ParseSwift/Parse.swift:106: Fatal error: Unexpectedly found nil while unwrapping an Optional value

Here is my AppDelegate:

@main
class AppDelegate: UIResponder, UIApplicationDelegate {

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        Task {
            guard let AppID = Secrets.App_ID,
              let ClientKey = Secrets.Cli_ID,
              let AppURL, let LiveURL
            else { fatalError("Incorrect implementation of Secrets") }
            let config = ParseConfiguration(AppID, ClientKey, AppURL, LiveURL)
            try await initialize(configuration: config)
        }
        return true
    }

}

I was hesitant to report it since I can't reproduce it consistently, but I thought I'd flag it anyway just in case you:
(a) wanted to know, and/or
(b) had any insight as to what might be causing the issue.
It definitely does crash with the same error if I comment out the Task in didFinishLaunching and then run a query.
My guess therefore is that it is some sort of issue with the login task being de-prioritised over some other Parse function like a query.

Line 106 is the following:

l104    /// The current `ParseConfiguration` for the ParseSwift client.
l105    public var configuration: ParseConfiguration {
l106        Parse.configuration
l107    }

Questions

  1. Is my AppDelegate code the intended way for Parse to be initialised?
  2. Is there a way to guarantee the login task completes either before returning from didFinishLaunching, or at least completes first before any other Tasks?
  3. Is it wise/possible to 'bake' into ParseSwift a means of ensuring that a query won't run until after the initialize function has completed? For example, a flag that makes those other tasks continue waiting until after initialize has returned.
@cbaker6 cbaker6 linked a pull request Mar 30, 2024 that will close this issue
5 tasks
@cbaker6
Copy link
Member Author

cbaker6 commented Apr 1, 2024

This issue occurs when using the == query constraint mixed with using the old appDelegate` lifecycle. Workarounds for this are described in #167 (reply in thread)

A fix to the == QueryConstraint will be added to the SDK in 6.0.0 5.11.5

@cbaker6 cbaker6 reopened this Apr 1, 2024
@cbaker6 cbaker6 added the bug Something isn't working label Jul 13, 2024
@cbaker6 cbaker6 linked a pull request Feb 27, 2025 that will close this issue
5 tasks
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
1 participant