-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
firestore.CreateIfMissingOption should be replaced #4111
Comments
A list of things that need to change:
In spirit, users will be able to use the "set with merge" operation wherever they previously used the "update and create if missing", however there are a few key differences. Update operations on
If I want to update only my city to ref.update({
u'address.city': u'LA'
}, firestore.CreateIfMissingOption(True)) Now I would do: ref.set({
u'address': {
u'city': u'LA'
}
}, firestore.MergeOption()) Notice that this is a deep merge meaning that if the |
@jba FWIW @samtstern and I had previously discussed a way to map out what features are missing before starting the work on updating the API surface. As of now, this is the only "known" work to be done. |
@dhermes Can you give us an estimate for the completion of this change? |
Does Python handle set/merge with deletes? There are also the conformance tests. I started work on this (#4359) but can't get anyone to look at it. |
The Python API was not updated after the last API change. It would only handle them if the client never added validation to reject these sets in the first place, but I would have to dig through the code to find out. |
@chemelnucfin Can you provide an estimate for this issue? |
@schmidt-sebastian Sorry I didn't realize I should be looking at this. I'll take a look right away. |
@samtstern Hi, I'm relatively new here so I'm not too familiar with protobuf, but it doesn't seem like there is a good option within protobuf in python to do what you want. MergeFrom creates 2 duplicate keys for the example you gave. I can try to fix it locally, but would it be better to work on the problem on the protobuf side? |
This is basically what it looks like: |
The Protobuf representation of the set() and the update() example that Sam provided is the same (and the one you provided in the update.pb example). The main difference is that set() takes a literal object value and that we extract the field paths from it, whereas update takes a list of field path/value pairs. When a user calls |
@schmidt-sebastian @samtstern It doesn't seem like the current code also merge properly doing the update and create_if_missing, but I may have the code wrong. |
In the create_and_update example you linked, you are updating the field For |
Thanks, that made it a lot clearer. |
@schmidt-sebastian After working on the PR for this, I realized there is a design question needed to be discussed. Are there likely going to be more write options in the future? Currently, the way it is implemented is using a kwargs: However, |
We do something similar with the Mobile SDKs. Take a look here: https://github.com/firebase/firebase-js-sdk/blob/453677f005d04e47be2324b9c1577051139652c0/packages/firestore/src/api/user_data_converter.ts#L115 We have four different 'parse modes': Set, Update, MergeSet, and QueryValue. Looks like you could do something similar and do Set, Update, MergeSet and Delete. For now, we don't have any plans on adding more options to SetOptions. But no promises :) |
See #4851 |
Remove `CreateIfMissing` option Closes #4111.
Paraphrased from @samtstern:
It's still possible to do
The other Firestore SDKs have removed this option and moved to an option on the
set()
operation called,merge()
. For example, in the Android SDK:The new semantics make it so that the
set()
operation (andcreate()
which some SDKs offer) is the only operation which can make a new document. Themerge()
option means that the data will be deep merged into any existing document, rather than just obliterating and replacing.The text was updated successfully, but these errors were encountered: