Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: SERVER_TIMESTAMP should survive deep copies (#820) #821

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions google/cloud/firestore_v1/transforms.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading