Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

fix(firestore): fix an issue that would cause FieldValue.increment to not work for big int #12426

Merged
merged 1 commit into from
Mar 5, 2024

Conversation

Lyokone
Copy link
Contributor

@Lyokone Lyokone commented Mar 4, 2024

Description

Replace this paragraph with a description of what this PR is doing. If you're modifying existing behavior, describe the existing behavior, how this PR is changing it, and what motivated the change.

Related Issues

closes #12318

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]).
This will ensure a smooth and quick review process. Updating the pubspec.yaml and changelogs is not required.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • My PR includes unit or integration tests for all changed/updated/fixed behaviors (See Contributor Guide).
  • All existing and new tests are passing.
  • I updated/added relevant documentation (doc comments with ///).
  • The analyzer (melos run analyze) does not report any problems on my PR.
  • I read and followed the Flutter Style Guide.
  • I signed the CLA.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change.
  • No, this is not a breaking change.

@Lyokone Lyokone merged commit a776dec into master Mar 5, 2024
21 checks passed
@Lyokone Lyokone deleted the fix/12318 branch March 5, 2024 10:57
@nbergemann
Copy link

Hello,

I've observed a change in behavior when using FieldValue.increment(1) with cloud_firestore after updating to a new version. Previously, when incrementing a field in Firestore, the incremented value would be received as an integer. However, now it appears to be received as a double.

The relevant code modification seems to be in packages/cloud_firestore/cloud_firestore_platform_interface/lib/src/method_channel/utils/firestore_message_codec.dart, where an adjustment was made to handle FieldValueType.incrementInteger as (delegate.value as int).toDouble() internally, to avoid precision loss:

} else if (value is FieldValuePlatform) {
    MethodChannelFieldValue delegate = FieldValuePlatform.getDelegate(value);
    final int code = _kFieldValueCodes[delegate.type]!;
-    buffer.putUint8(code);
-    if (delegate.value != null) writeValue(buffer, delegate.value);
+    if (delegate.type == FieldValueType.incrementInteger) {
+        buffer.putUint8(_kIncrementDouble);
+        writeValue(buffer, (delegate.value as int).toDouble());
+    } else {
+        buffer.putUint8(code);
+        if (delegate.value != null) writeValue(buffer, delegate.value);
+    }
}

Is this change intentional? It seems to introduce inconsistencies with how incremental updates are handled and serialized. For a temporary workaround, I've specified cloud_firestore_platform_interface: 6.1.7 in my pubspec.yaml.

Could someone clarify if this is the intended behavior moving forward and suggest how we might adjust our code to accommodate this change effectively?

Thank you.

@nekooooo0203
Copy link

as double? causes error, type 'int' is not a subtype of type 'double?' in type cast
as int? causes error, type 'double' is not a subtype of type 'int?' in type cast

@Lyokone
Copy link
Contributor Author

Lyokone commented Mar 7, 2024

Already reported and tracked here: #12436

@firebase firebase locked and limited conversation to collaborators Apr 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🐛 [cloud_firestore] Error with Firestore Increment Value for Large Integers
5 participants