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

Integration tests and FSTUserDataConverter fixes for array transforms. #1108

Merged
merged 5 commits into from
Apr 17, 2018

Conversation

mikelehen
Copy link
Contributor

No description provided.

Copy link
Contributor

@wilhuff wilhuff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the tests. One nit and a question.

@@ -276,6 +276,13 @@ - (void)deleteDocumentRef:(FIRDocumentReference *)ref {
[self awaitExpectations];
}

- (void)mergeDocumentRef:(FIRDocumentReference *)ref data:(NSDictionary<NSString *, id> *)data {
[ref setData:data
merge:TRUE
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/TRUE/YES/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gah, woops! Good catch.

} else if ([input isKindOfClass:[FIRFieldValue class]]) {
// parseSentinelFieldValue may add an FSTFieldTransform, but nothing should be included in
// the actual parsed data, so we don't add this path to our fieldMask and we return nil.
[self parseSentinelFieldValue:(FIRFieldValue *)input context:context];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is no longer calling [context appendToFieldMaskWithFieldPath:*context.path] which doesn't seem right.

If I update(["a.b": FieldValue.serverTimestamp()]) shouldn't there be a field mask for "a.b"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, no... and that's the bug I was fixing. With serverTimestamp() it doesn't actually matter (so the existing code was "wrong" but non-harmful), but if you do:

update(["a": 42, "b": FieldValue.arrayUnion("added")])

We parse that into two mutations:

  1. PatchMutation with fieldMask a and data {a: 42}
  2. TransformMutation with [b => arrayUnion("added")]

It's critical that mutation #1 does not include "b" in the fieldMask, else it'll end up clearing the array prior to the TransformMutation adding "added" to it.

And so the code here needs to not appendToFieldMask when a value parses into a transform. (note that FieldValue.delete() is not a transform, so I had to add code below to still add to the FieldMask in that case)

I expanded on the comment to hopefully make it a bit clearer.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. Thanks for explaining.

@wilhuff wilhuff assigned mikelehen and unassigned wilhuff Apr 15, 2018
Copy link
Contributor Author

@mikelehen mikelehen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PTAL

@@ -276,6 +276,13 @@ - (void)deleteDocumentRef:(FIRDocumentReference *)ref {
[self awaitExpectations];
}

- (void)mergeDocumentRef:(FIRDocumentReference *)ref data:(NSDictionary<NSString *, id> *)data {
[ref setData:data
merge:TRUE
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gah, woops! Good catch.

} else if ([input isKindOfClass:[FIRFieldValue class]]) {
// parseSentinelFieldValue may add an FSTFieldTransform, but nothing should be included in
// the actual parsed data, so we don't add this path to our fieldMask and we return nil.
[self parseSentinelFieldValue:(FIRFieldValue *)input context:context];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, no... and that's the bug I was fixing. With serverTimestamp() it doesn't actually matter (so the existing code was "wrong" but non-harmful), but if you do:

update(["a": 42, "b": FieldValue.arrayUnion("added")])

We parse that into two mutations:

  1. PatchMutation with fieldMask a and data {a: 42}
  2. TransformMutation with [b => arrayUnion("added")]

It's critical that mutation #1 does not include "b" in the fieldMask, else it'll end up clearing the array prior to the TransformMutation adding "added" to it.

And so the code here needs to not appendToFieldMask when a value parses into a transform. (note that FieldValue.delete() is not a transform, so I had to add code below to still add to the FieldMask in that case)

I expanded on the comment to hopefully make it a bit clearer.

@mikelehen mikelehen assigned wilhuff and unassigned mikelehen Apr 16, 2018
Copy link
Contributor

@wilhuff wilhuff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

} else if ([input isKindOfClass:[FIRFieldValue class]]) {
// parseSentinelFieldValue may add an FSTFieldTransform, but nothing should be included in
// the actual parsed data, so we don't add this path to our fieldMask and we return nil.
[self parseSentinelFieldValue:(FIRFieldValue *)input context:context];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. Thanks for explaining.

@mikelehen mikelehen assigned mikelehen and unassigned wilhuff Apr 16, 2018
@mikelehen
Copy link
Contributor Author

I'll re-target to master and merge once the prereq PRs land...

@mikelehen mikelehen force-pushed the mikelehen/array-transforms-tests-and-fixes branch from 5dc00b4 to 6e08e8c Compare April 17, 2018 22:12
@mikelehen mikelehen changed the base branch from mikelehen/array-transforms-serialization to master April 17, 2018 22:13
@mikelehen mikelehen merged commit e36cc96 into master Apr 17, 2018
@mikelehen mikelehen deleted the mikelehen/array-transforms-tests-and-fixes branch April 17, 2018 22:55
minafarid pushed a commit to minafarid/firebase-ios-sdk that referenced this pull request Jun 6, 2018
@firebase firebase locked and limited conversation to collaborators Nov 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants