Comments (10)
I guess I figured it out. Using Typescript/Javascript, it was impossible for me to explicitly use a double type for numbers without the fractional part, like 0, 10, 123, etc. I was able to do that with Dart, that's why my normal users don't experience the problem. Furthermore the Firebase consol only shows the values as "number" is something that made it more confusing to me when there're actually 2 types of number supported: https://firebase.google.com/docs/firestore/manage-data/data-types
I had to use a Python function to do the copy. Problem fixed.
from flutterfire.
Hello @larssn, thank you for reporting this issue. I wasn't able to reproduce it. Here's the code I used, and it ran without errors:
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
FirebaseFirestore.instance.settings = const Settings(
persistenceEnabled: true,
);
if (shouldUseFirestoreEmulator) {
FirebaseFirestore.instance.useFirestoreEmulator('localhost', 8080);
}
runApp(TheApp());
}
class TheApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Center(
child: ElevatedButton(
onPressed: () async {
try {
// Update operation
FirebaseFirestore firestore = FirebaseFirestore.instance;
DocumentReference documentReference =
firestore.collection('test_10153').doc('counter');
final doc = await documentReference.get();
if (!doc.exists) {
await documentReference.set(<String, dynamic>{});
}
await documentReference.update({'counter': FieldValue.increment(1)});
// Attempt to fetch and deserialize the updated document
DocumentSnapshot snapshot = await documentReference.get();
Map<dynamic, dynamic>? data = snapshot.data() as Map<dynamic, dynamic>?;
if (data != null) {
// Directly deserialize 'counter' field within fromFirestore
int? counter = data['counter'] as int?;
print('Deserialized counter value: $counter');
}
} on Exception catch (error, stackTrace) {
debugPrint(error.toString());
debugPrintStack(stackTrace: stackTrace);
}
},
child: Text('Increment Counter and Deserialize'),
),
),
),
);
}
}
I suggest you update all your plugins to the latest version and try again. If the issue still persists, please provide a reproduction code or repo that is failing.
from flutterfire.
They are all the latest version, and I just experienced this issue today.
And I have used FieldValue.increment
without issues, but the error seems periodic.
from flutterfire.
What's the size of the vlaue you are trying to increment and by how much you are incrementing it?
from flutterfire.
Not much, in my tests I used about -5 to +5.
And the size incremented/subtracted, is about the same.
from flutterfire.
I'm seeing a kind of similar issue:
_TypeError: type 'int' is not a subtype of type 'double' in type cast
This happens at this line:
final double graceAmount = snap.get('grace_amount') != null ? snap.get('grace_amount') as double : 0;
The thing is this still works fine for most of my users. Meaning snap.get('grace_amount')
returns 0.0
for most of them. But yesterday when I tried to copy all the documents of a user to another, the new user encounter this issue. For this case snap.get('grace_amount')
returns 0
. So I guess something has changed from firestore end.
This is the firebase function that I used:
const { sourceUserID, destUserID } = request.body;
if (!sourceUserID || !destUserID) {
logger.warn("Missing sourceUserID or destUserID.");
response.sendStatus(400);
}
try {
const sourceRef = getFirestore().collection("users").doc(sourceUserID);
const destRef = getFirestore().collection("users").doc(destUserID);
// Copy subcollections
const sourceCollections = await sourceRef.listCollections();
for (const collection of sourceCollections) {
const collectionRef = sourceRef.collection(collection.id);
const destCollectionRef = destRef.collection(collection.id);
const collectionSnapshot = await collectionRef.get();
for (const doc of collectionSnapshot.docs) {
await destCollectionRef.doc(doc.id).set(doc.data(), { merge: true });
}
}
logger.info("Documents copied successfully");
} catch (error) {
logger.error("Error copying documents");
}
from flutterfire.
@minhdanh Thank you for sharing these details, appreciated.
@larssn Can you investigate if your issue is similar to the one @minhdanh mentioned? Since I couldn't get issue to happen when testing.
from flutterfire.
Ours is in pure dart, no web involved, so I doubt it's the same issue.
The "fix" was changing the int directly in firestore (away from 0 and back to 0), which caused the issue to go away.
I still think this part was weird, and is probably significant.
from flutterfire.
for me I simply us num instead of int and then num.toInt()
from flutterfire.
We use the workaround on incoming data as well, but I'd prefer we wouldn't have to.
from flutterfire.
Related Issues (20)
- [firebase_analytics]: Crashlytics doesn't track screen view breadcrumbs HOT 9
- [cloud_firestore]: iOS includeMetadataChanges on document snapshots does not receive fromCache events correctly HOT 1
- [📚] Your documentation feedback title (CHANGE ME)
- [firebase_auth]: Can't use verifyPhoneNumber before updating the phone number? HOT 2
- 🐛 [flutter_facebook_auth] Automatically verify email addresses with Facebook sign-in HOT 2
- [firebase_analytics]: Firebase Analytics 10.10.5 and 10.10.4 version cannot build Android HOT 7
- [firebase_auth]: error.credential is null on credential-already-in-use exception during apple sign in in web HOT 3
- [firebase_auth]: [firebase_auth/app-not-authorized] This app is not authorized to use Firebase Authentication. Please verify that the correct package name, SHA-1, and SHA-256 are configured in the Firebase Console. [ Invalid app info in play_integrity_token ] HOT 5
- [📚] Your documentation feedback title (CHANGE ME)
- [flutterfire_cli]: v1.0.0 update command fails on Windows HOT 1
- [ALL] Consider adding `topics` to `pubspec.yaml` for better discoverability HOT 1
- [FIRESTORE]: includeMetadataChanges does not make the stream emit second non cache event HOT 1
- [firebase_crashlytics] 此应用有 1 个崩溃问题未处理。请上传 1 个 dSYM 文件以处理崩溃问题。 HOT 1
- [firebase_analytics]: What is the higher minimum MacOS deployment version for the last version HOT 1
- [firebase_analytics]: <firebase_analytics does not work in Android, after migrating build.gradle > HOT 2
- [firebase_analytics]: logPurchase crashes when any of the values inside parameters is null HOT 2
- [FIIREBASE_AUTH] Unable to establish connection on channel. HOT 2
- [📚] [firebase_messaging_web] How to load on Flutter 3.22? HOT 1
- [firebase_app_check]: The new Firebase App Check token is not being updated in Firestore and other services that have App Check enforced. HOT 3
- [FIREBASE_STORAGE] mime/contentType undefined after upploading files to firebase storage if settableMetadata is NOT null
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flutterfire.