Comments (16)
Just to make sure I understood correct, how would it be different from the existing transaction()
or set_if_unchanged()
methods? By performing an update instead of a full overwrite (HTTP PATCH as opposed to PUT)?
Not sure if the server API supports that kind of an operation. @caseycrogers, does this sound like something we can do?
from firebase-admin-python.
from firebase-admin-python.
I'm not convinced that this can be implemented without server-side support. For instance suppose you do:
data, etag = ref.get(etag=True)
make_changes_to(data)
if etag == ref.etag():
# Foo
ref.update(data)
If another client updates data in the server at #Foo
, we will overwrite the change leading to the lost-update problem. We need an atomic, server-supported update-if-unchanged operation for this.
@caseycrogers @rockwotj Does the existing conditional requests support provide something like that?
from firebase-admin-python.
@hiranya911, any updates on this? Also, is there documentation about how transactions are done in the new Firestore database? I wasn't able to find anything. Thanks.
from firebase-admin-python.
Sorry I missed this. What you do you by update-if-unchanged? You want to two 2 writes and make sure no data is changed inbetween them you just need to set the same 'X-Firebase-ETag: true'
header in the write and you'll get the ETag back just if you did a read there right after the operation is done. You can use that etag in the next write.
As for Firestore transactions, here are the python docs (which I guess that's what you want): https://googlecloudplatform.github.io/google-cloud-python/latest/firestore/transaction.html
Firestore transactions are much more powerful and let you do full read/write operations atomically.
from firebase-admin-python.
Hi @rockwotj. The SDK currently supports a set_if_unchanged()
method which handles this. I guess the question is can we support a similar update_if_unchanged()
method. In REST terms can we do a conditional PATCH
request?
from firebase-admin-python.
Yeah you can do it with PATCH
too
from firebase-admin-python.
Thanks @rockwotj.
@alexanderwhatley Would you be interested in providing us a PR? I assume it will be very similar to the existing set_if_unchanged()
, except using HTTP patch
method instead of put
.
from firebase-admin-python.
Sure @hiranya911, I'll get something up by tomorrow hopefully.
from firebase-admin-python.
And on a tangential, Firestore support for Python admin SDK is being developed at #79.
from firebase-admin-python.
A quick correction, none of the conditional request features (ie ETags, if-none-match) are supported with the PATCH method.
This is because, with PATCH, it's unclear what should be used to compute the ETag.
I'm not entirely sure what you mean by "set" vs. "update". Do you mean PUT vs. PATCH? If so, any PATCH requests can be converted into one or more PUT requests and you can use the set_if_unchanged method.
from firebase-admin-python.
Oh! I was afraid of this.
And just to clarify @caseycrogers, you're right.
- set = PUT = total overwrite
- update = PATCH = selective update of children
The problem with implementing update_if_unchanged()
as a series of PUT operations is, then it is no longer atomic. I think @alexanderwhatley is trying to read a parent object along with its etag, and then atomically update some of its children. Something like:
data, etag = ref.get(etag=True)
update = {'foo' : 'bar', 'baz' : data.get('baz') + 1}
ref.update_if_unchanged(update, etag) # This should ideally be a single REST call
from firebase-admin-python.
@alexanderwhatley can we get some more context There might be some easy ways to rewrite your code not to depend on patch depending on how your data is structured and what exactly you are trying to achieve.
from firebase-admin-python.
@caseycrogers, I am trying to do what hiranya is saying, which doesn't appear possible right now. I most likely will just switch to using Firestore anyways, which appears to support this kind of transaction, so this should be a nonissue.
from firebase-admin-python.
What solution will work best for you will depend heavily on your data structure. It may be that the Database's transactions implementation will suit your needs well without the need for an update/PATCH.
However, as you said, this may be a non-issue given that Firestore's transactions support update operations. Let me know if you decide to proceed with this in the Database.
from firebase-admin-python.
I'm closing this since the backend API doesn't seem to support this. We can revisit this if this turns out to be a critical use case.
from firebase-admin-python.
Related Issues (20)
- Couldn't import app_check HOT 1
- Firebase functions container silently freezes on making a get request to Firestore if multiple requests were created before container starts HOT 3
- Call to Firestore getting timed out from the docker container. HOT 1
- Querying Firestore documents by nested key-value in an array field using Python HOT 1
- firestore times out when using default DNS resolver HOT 1
- [FR] Async `messaging` requests HOT 1
- import firebase admin HOT 3
- Using cloud run from gcp console to firebase HOT 1
- Cloud run from gcp console HOT 2
- [FR][FCM] HTTP2 support for sendEach HOT 9
- [FR] Change the firestore db in firestore.client. HOT 1
- Datastore emulator causes firebase admin to hang HOT 2
- Realtime Database Listener Crashes on Internet Disconnection HOT 1
- Better Error handling for empty token list in Messaging send_each_multicast HOT 1
- Documentation: API Reference not available HOT 1
- Connection aborted in google/oauth2 affecting firebase HOT 1
- verify_token() got an unexpected keyword argument 'clock_skew_in_seconds' HOT 1
- Add google/microsoft providers for a tenant using python library
- Please fix
- Message.data must be a dictionary. HOT 2
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 firebase-admin-python.