Skip to content

Commit

Permalink
feat: SERVER_TIMESTAMP should survive deep copies (googleapis#820)
Browse files Browse the repository at this point in the history
* Add dunder copy and deepcopy to Sentinel
  • Loading branch information
mgraczyk committed Dec 12, 2023
1 parent 85d0ab8 commit b39bb35
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
9 changes: 9 additions & 0 deletions google/cloud/firestore_v1/transforms.py
Expand Up @@ -26,6 +26,15 @@ def __init__(self, description) -> None:
def __repr__(self):
return "Sentinel: {}".format(self.description)

def __copy__(self):
# Sentinel identity should be preserved across copies.
return self

def __deepcopy__(self, memo):
# Sentinel identity should be preserved across deep copies.
return self



DELETE_FIELD = Sentinel("Value used to delete a field in a document.")

Expand Down
20 changes: 20 additions & 0 deletions tests/unit/v1/test_transforms.py
Expand Up @@ -114,3 +114,23 @@ def test__numericvalue___eq___same_value():
inst = _make_numeric_value(value)
other = _make_numeric_value(value)
assert inst == other


def test__server_timestamp_is_same_after_copy():
from google.cloud.firestore_v1.transforms import SERVER_TIMESTAMP
import copy

value = SERVER_TIMESTAMP

value_copy = copy.copy(value)
assert value_copy is value


def test__server_timestamp_is_same_after_deepcopy():
from google.cloud.firestore_v1.transforms import SERVER_TIMESTAMP
import copy

value = SERVER_TIMESTAMP

value_copy = copy.deepcopy(value)
assert value_copy is value

0 comments on commit b39bb35

Please sign in to comment.