Skip to content

Commit

Permalink
feat: SERVER_TIMESTAMP should survive deep copies (#820) (#821)
Browse files Browse the repository at this point in the history
  • Loading branch information
mgraczyk committed Dec 13, 2023
1 parent 81865ee commit 2b17705
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
8 changes: 8 additions & 0 deletions google/cloud/firestore_v1/transforms.py
Expand Up @@ -26,6 +26,14 @@ 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 2b17705

Please sign in to comment.