You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently the second assertion fails because the Sentinel has been deep copied.
Traceback (most recent call last):
File "/Users/michael/dev/rfp-tool/test.py", line 15, in <module>
assert asdict['timestamp'] is SERVER_TIMESTAMP
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError
Solution
The Sentinel class should define dunder __copy__ and __deepcopy__ methods.
diff --git a/google/cloud/firestore_v1/transforms.py b/google/cloud/firestore_v1/transforms.py
index f1361c9..ef0def8 100644
--- a/google/cloud/firestore_v1/transforms.py
+++ b/google/cloud/firestore_v1/transforms.py
@@ -26,6 +26,15 @@ class Sentinel(object):
def __repr__(self):
return "Sentinel: {}".format(self.description)
+ def __copy__(self):
+ # Sentinel identity should be preserved across copies.
+ return self
+
+ def __deepcopy__(self):
+ # Sentinel identity should be preserved across deep copies.
+ return self
+
+
DELETE_FIELD = Sentinel("Value used to delete a field in a document.")
I will send a PR attached to this issue.
The text was updated successfully, but these errors were encountered:
Problem
Currently
SERVER_TIMESTAMP
does not work if it has been copied viacopy.deepcopy
.This is especially important for
dataclasses
.Here is an example script to demonstrate the problem
Currently the second assertion fails because the Sentinel has been deep copied.
Solution
The Sentinel class should define dunder
__copy__
and__deepcopy__
methods.I will send a PR attached to this issue.
The text was updated successfully, but these errors were encountered: