-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Make Firestore use FirebaseDataEncoder and FirebaseDataDecoder (re-implementation of #8858) #9465
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
Make Firestore use FirebaseDataEncoder and FirebaseDataDecoder (re-implementation of #8858) #9465
Conversation
…DataEncoder. Refactor isPassthroughType to be non-generic later.
This reverts commit 5814f48.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's great to remove so many lines of code. thanks!
Do you need help resolving the PassthroughType related CI failures?
That would be great - I assume they are due to using a fixed version of There are currently two failing tests in I think that the behavior of With regards to throwing at conflicting document id fields, I think that I mentioned on the other PR that I think that this is a quite harsh behavior that makes it hard to evolve your models towards using document ids or away from them - if old data models with old ids make your code crash. So I'd recommend that this behavior was removed on purpose. |
|
@mortenbekditlevsen See #9493 for CI fixes @peterfriese @ryanwilson @schmidt-sebastian Any thoughts about Morten's other questions? |
|
To clarify my uncertainty about If this is true, the behavior is asymmetric with the decoding, where at least it appears that a I would suggest that the default encoding strategy of a There's of course a whole other discussion about why |
|
Thanks @mortenbekditlevsen This Date discussion maps to these current CI test failures: Failing tests: |
|
The first one, yes. The second failure is related to my question about whether the presence of eg an 'id' property in data decoded with a DocumentID called 'id' should actually fail. I think that it should not because it complicates evolution of your models. So I think that test case should just be deleted. |
|
Ok, I found out that my initial testing of the |
|
Sorry, I was out of office for a couple of days. Looks like you were able to find answers to your questions. Firestore accepts Dates and Timestamps as input but by default only returns Timestamps. For customers that use Codable, we can deviate from the default when we know that the resulting type is meant to be a Date. This still seems to be the case if I understand I don't have a strong opinion in regards to the DoumcentID validation. I agree that it makes it harder to migrate data models, so it seems reasonable to remove this validation. |
|
What is outstanding on this PR besides a CHANGELOG update? @mortenbekditlevsen @peterfriese @schmidt-sebastian @ryanwilson |
|
Hi Paul, But actually the always in the current decoder only needs to translate to 'by default'. Meaning that the default date decoding strategy for the Firestore decoder would just be a 'timestamp' decoder that looks like: This doesn't mean that the fallback behavior that I already implemented can't be of value, but it complicates the API a bit and it can of course be implemented by the user if one really wishes that behavior. What do you think? Should I go ahead and do the simpler |
|
@mortenbekditlevsen It sounds like you're saying that there is no difference in behavior between the two implementations. In that case, it sounds good to me to go ahead and update to the simpler implementation. |
Well, not exactly, but the default behavior (and thus the compatibility with previous versions) is the same and I don't think there's a whole lot of value in the more complex behavior. |
|
Thanks @mortenbekditlevsen! That looks much more maintainable. Would you resolve the conflict with the |
|
Sure, I'll take a look at it later today. |
|
Hi @chliangGoogle , |
|
@mortenbekditlevsen I think we just forget to move this to the next release as we are releasing the previous release. |
|
@mortenbekditlevsen Sorry that we've been so slow at landing this PR. I'd really like to get it in before our code freeze deadline for Firebase 10.0.0 in the next week or so. Reading through the comments, I see a few open questions, but I'm not sure what exactly still needs to be resolved to merge. Given that 10.0.0 is a breaking change release, we can allow some breakages if we document them and believe they're only used in corner cases. Is it possible to update the Firestore CHANGELOG that summarizes the implications for the API's clients? |
|
I'll have a look at it tomorrow evening. There may not be any breaking changes after all. I'll have a look and suggest an addition to the change log. |
|
I added the following to the CHANGELOG - please let me know if you think it requires more details: 10.0.0
|
|
With regards to breaking changes, I think that the way we ended up implementing it - by wrapping the shared encoder and decoder instead of just making it be a typealias to the shared encoder and decoder - ended up giving it a fully backwards compatible API surface. I'm not certain how to prove this, however. Isn't there some api checker tool that can verify this externally? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @mortenbekditlevsen. Would it feasible to add tests for the new customization options?
|
The various encoding and decoding strategies are tested thoroughly in |
|
Thanks @mortenbekditlevsen. Those tests would be useful, although not necessarily blocking for this PR to merge. We're planning to code freeze for Firebase 10 on September 27. |
|
The API review is still awaiting final approval, and I'm going to merge here to get into the Firebase 10 testing. |
* [Firebase 10] Bump 9.X versions to 10.0.0 * Bump min. GTMSessionFetcher dep version to 2.1 * Bump min. GDT dep version to 9.2 * Bump min. GULs dep version to 7.8 * Fix unintentional nanopb replace * Fix unintentional nanopb replace (2) * Fix unintentional nanopb replace (3) * Fix unintentional nanopb replace (4) * Fix unintentional nanopb replace (4) * Trigger all CI * Bump FirebaseCombineSwift to 10 * Fix FirebaseStorage.podspec I'm not sure what happened here. I had committed it during the rebase but guess not? * Fix unintentional nanopb replace (5) * Disable two tests to unblock staging * Fix and re-enable FIROptions tests * Update deployment targets in Firebase.podspec * Add CHANGELOG entry for GTMSessionFetcher * Fix AppCheck iOS availability * Fix inadvertent API change (#10245) * Docs update for Extensions and putFile (#10248) * App google domain support (#10249) Adding new 1p domain "app.google" support in FDL SDK. * Remote Config Dynamic Property Wrapper (#10155) * Separate GoogleUtilities Carthage build (#10250) * Public count (#10246) * Public Count * Swift Test Commit * Swift Format * No extra whitespace * Hopefully formatted. * Change log and feedback. * Revert "Public count (#10246)" (#10252) This reverts commit 8aae6be. * Make Firestore use FirebaseDataEncoder and FirebaseDataDecoder (re-implementation of #8858) (#9465) * Bump tvOS minimum support version to 12.0 * [skip ci] Revert Gemfile Co-authored-by: Paul Beusterien <paulbeusterien@google.com> Co-authored-by: Eldhose M Babu <eldhosembabu@google.com> Co-authored-by: Charlotte Liang <chliang@google.com> Co-authored-by: wu-hui <53845758+wu-hui@users.noreply.github.com> Co-authored-by: Morten Bek Ditlevsen <bek@termestrup.dk>
| @@ -1,3 +1,14 @@ | |||
| # 10.0.0 | |||
| - [changed] `Firestore.Encoder` and `Firestore.Decoder` now wraps the shared `FirebaseDataEncoder` and `FirebaseDataDecoder` types which provides new customization options for encoding and decoding date to and from Firestore - similar to the options present on `JSONEncoder` and `JSONDecoder` from `Foundation`. | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: "options for encoding and decoding date" date --> data or data types?
| @@ -1,3 +1,14 @@ | |||
| # 10.0.0 | |||
| - [changed] `Firestore.Encoder` and `Firestore.Decoder` now wraps the shared `FirebaseDataEncoder` and `FirebaseDataDecoder` types which provides new customization options for encoding and decoding date to and from Firestore - similar to the options present on `JSONEncoder` and `JSONDecoder` from `Foundation`. | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: should this be line wrapped?
Continuing the discussion from PR #8858 here.
This PR makes Firestore use the
FirebasesDataEncoderandFirebaseDataDecoder- bringing key coding strategies, etc. to the encoding, while attempting to be compatible with the existing encoder and decoder.After restructuring of Firestore and FirebaseSharedSwift it was too hard for me to merge into the branch from #8858.
I still need to implement tests - since #8858 I have learned how to run tests by @peterfriese - thanks! :-)
I have a feeling that the
CodablePassthroughTypesisn't working as it is being passed type erased values. Needs to be done throughiscasting/checking instead.Internal API review at go/firestore-data-encoding-strategies-api