diff --git a/google/cloud/firestore_v1/transforms.py b/google/cloud/firestore_v1/transforms.py index f1361c951..52c4d1eb7 100644 --- a/google/cloud/firestore_v1/transforms.py +++ b/google/cloud/firestore_v1/transforms.py @@ -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.") diff --git a/tests/unit/v1/test_transforms.py b/tests/unit/v1/test_transforms.py index 218650bb5..1a46f2721 100644 --- a/tests/unit/v1/test_transforms.py +++ b/tests/unit/v1/test_transforms.py @@ -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