sdk-for-apple: π Bug Report: Crash with Query select, AppwriteModels/Document.swift:94: Fatal error: Unexpectedly found nil
π Reproduction steps
When I attempt to perform a simple query operation which includes a select, the Appwrite code crashes
The setup is very simple; thereβs a collection of Books as shown in the documentation. Each Book has two properties, title and author (again per the documentation).
The query is for document title matching Book A and I want to return only the title and author properties. (yes, I know thatβs the only two but for this report it demonstrates the bug)
If in the below code the queries section is removed OR the select statement is removed, the query works properly.
The code:
func outputSampleBooks() async throws {
do {
let documentList = try await databases.listDocuments(
databaseId: databaseId,
collectionId: collectionId,
queries: [
Query.equal("title", value: "Book A"),
Query.select(["title", "author"])
]
)
} catch {
print(error)
}
}
The books collection is attached below
and then the crash:
AppwriteModels/Document.swift:94: Fatal error: Unexpectedly found nil while unwrapping an Optional value
The crash is located in AppwriteModels->DocumentList.swift->from(map:)
public static func from(map: [String: Any] ) -> DocumentList {
return DocumentList(
total: map["total"] as! Int,
documents: (map["documents"] as! [[String: Any]]).map { Document.from(map: $0) } //crash
)
}
π Expected behavior
It should⦠not crash
π Actual Behavior
It actually crashes whenever the query includes a select statement
π² Appwrite version
Different version (specify in environment)
π» Operating system
Linux
π§± Your Environment
AppWrite sdk-for-apple 9.0.1 XCode 16 macOS Sequoia 15.5
Iβve duplicated this on several workstations with similar setups
π Have you spent some time to check if this issue has been raised before?
- I checked and didnβt find similar issue
π’ Have you read the Code of Conduct?
- I have read the Code of Conduct
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 18 (11 by maintainers)
@ChiragAgg5k Queries with select is now working. Thank you so much!
The Book struct now looks like this: it has a structure where all properties (that may appear in a query select) are marked as optional
and these all work