Firestore Data Bundles doesn't support empty Array and empty Map
My environment
- Xcode version: 13.2.1
- Firebase SDK version: 8.12.1
- Installation method:
CocoaPods - Firebase Component: Firestore
- Target platform(s):
iOS
Problem
Steps to reproduce:
Context
To reduce firestore cost, I'm trying to use Firestore Data Bundles for my project.
Steps
- [Cloud Function] Get
my-home-usersfirestore query snapshot by using Firebase Admin SDK and bundle them into txt file. - [Cloud Function] Upload the bundle txt file to GCS.
- [iOS] Load the bundle txt file from GCS.
When I create bundle txt file with firestore query snapshot data which doesn't include multi bytes string data I can get namedQuery in Swift.
However if I try to create bundle txt file which includes multi bytes string data like Japanese I failed to get it.
Relevant Code:
Cloud Functions
bundleHomeNewUsers.ts
import { getAdmin } from "../../util/firebase";
import * as firebase from "firebase-admin";
import * as fs from "fs";
export const bundleHomeNewUsers = async () => {
const BUCKET_NAME = "my-project-firestore-data-bundles";
const admin = getAdmin();
const db = admin.firestore();
const bundle = db.bundle("home-users");
const querySnapshot = await db
.collection("users")
.orderBy("createAt", "desc")
.limit(4)
.get();
const buffer = bundle.add("home-users-bundles-query", querySnapshot).build();
//Create tmp local file to upload
const bundledFilePath = `/tmp/bundle.txt`;
const charset = "utf8";
fs.writeFileSync(bundledFilePath, buffer, charset);
//Upload bundle file to Storage
const destination = `firestore-data-bundles/home_users_bundles.txt`;
await firebase
.storage()
.bucket(BUCKET_NAME)
.upload(bundledFilePath, {
destination,
public: true,
metadata: {
cacheControl: `public, max-age=60`,
contentType: "text/plain; charset=utf8",
},
});
console.log(
`Uploaded to https://storage.googleapis.com/${BUCKET_NAME}/${destination}`
);
};
Swift
FirestoreService.swift
let db = Firestore.firestore()
let urlString = "https://storage.googleapis.com/nadare-production-firestore-data-bundles/firestore-data-bundles/home_users_bundles.txt"
guard let url = URL(string: urlString),
let bundle = try? String(contentsOf: url, encoding: .utf8) else {
print("[DEBUG] loadHomeUsers: Not found bundle file")
return
}
db.loadBundle(Data(bundle.utf8)) { progress, error in
switch progress?.state {
case .success:
print("[DEBUG] success")
db.getQuery(named: "home-users-bundles-query") { query in
guard let query = query else {
print("[DEBUG] Failed to get named query")
return
}
print("[DEBUG] Succeeded to get queryπππ")
query.getDocuments(source: .cache) { snapshot, error in
if let error = error {
return
}
guard let snapshot = snapshot else {
return
}
observer.sendCompleted()
}
}
case .inProgress:
print("[DEBUG] inProgress case")
case .error:
print("[DEBUG] error case: \(error.debugDescription)")
default:
print("[DEBUG] default case")
}
}
Output
[DEBUG] Failed to get named query
Firebase SDK error log
Error Domain=FIRFirestoreErrorDomain Code=2 "Loading bundle failed with unknown error" UserInfo={NSLocalizedDescription=Loading bundle failed with unknown error})
8.12.1 - [Firebase/Firestore][I-FST000001] Failed to GetNextElement() from bundle with error 'values' is missing or is not an array
8.12.1 - [Firebase/Firestore][I-FST000001] Progress set to Error, but error_status() is ok()
I found a few problems with this issue:
- I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
- This issue does not have all the information required by the template. Looks like you forgot to fill out some sections. Please update the issue with more information.
Hi,
I tried to reproduce the issue on my side and it returns successfully when there are Japanese characters inside bundle.txt. If you need more support, you can share your bundle text file here or email me at [email protected].
Hi, @cherylEnkidu. Thanks for checking this issue. I've sent you an email with my file. Please check later.
Hi,
I look at the Latin1 encoded txt file you sent me and I think they are hand edited. Firestore data bundles can only support machine generated text file. Which means if you changing the txt content manually the functions wouldn't work. Hope it solves your question :)
Hi,
Which means if you changing the txt content manually the functions wouldn't work.
Yes, I know. But I didn't edit the content manually.
I think this time the Gmail client app changes the content a bit. Please see below.
Attached
- txt file (Latin1) in GCS
- Cloud Function code for bundling firestore data
2022εΉ΄3ζ5ζ₯(ε) 1:57 cherylEnkidu @.***>:
Hi,
I look at the Latin1 encoded txt file you sent me and I think they are hand edited. Firestore data bundles can only support machine generated text file. Which means if you changing the txt content manually the functions wouldn't work. Hope it solves your question :)
β Reply to this email directly, view it on GitHub https://github.com/firebase/firebase-ios-sdk/issues/9407#issuecomment-1059338677, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADYTYKZ34WCHPTAK24HCNOLU6I6HHANCNFSM5PXR2MWQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
You are receiving this because you authored the thread.Message ID: @.***>
Hi, Thanks for reporting this issue. We have found the bug and we will work on to fix it.
Great! I'm looking forward to it :)
Awesome!! Thank you @cherylEnkidu !!
@cherylEnkidu
Hi, Thank you for fix the issue. After updating the SDK to v8.1.5, I can load the bundle file in most cases.
However it's still failed when a document has empty Map.
If the document has empty Array, it's working. :)
Hi toco1001,
Thanks for your report, I will take a look at it and keep you updated :)
Hi toco1001, I have verified the bug exists and logged it in the list, it will be fixed in the future. Internal tracking ticket b/229750482
Hello @cherylEnkidu,
I am still seeing this issue over a year later. Is there any chance you can prioritize it soon?
@Kal-Elx Hi, there is no plan for fixing it recently. I will log your request in the tickets to help prioritize it in the future.
Hello,
We have this issue as well, is there any hope this might get fixed soon?
Hi , sorry for the delay, this bug fix hasn't been prioritized yet. I will update this ticket once it is fixed.
Hi folks, This ticket is still in our backup log, the team's current policy is closing the external bug tracking ticket (github issue) and maintaining the internal bug tracking ticket(b/229750482). This github ticket will get notified when the bug is fixed.
Hi,
The team decided to keep the ticket open until the feature is implemented or bug is fixed for external visibility.
@cherylEnkidu , please consider prioritizing this issue! Thank you!
Also waiting for a fix. After I added dummy data to every empty map and array for every document, the error has changed to
Failed to GetNextElement() from bundle with error Prefix string is not a valid number
I'm not sure if it is part of this bug or if I should open a new issue
Thank you for every developers who reply to this thread. The fix is coming out in the next release.