python-mock-firestore icon indicating copy to clipboard operation
python-mock-firestore copied to clipboard

Problem with transforms on empty document

Open alexlipa91 opened this issue 2 years ago • 0 comments

I found out that writing transforms, for example increments, on an empty doc stores the actual objects in the in-memory db, e.g.

# some code writing to the db

print(db.collection("users").document("user_one").get().to_dict())


{'num_matches_joined': <google.cloud.firestore_v1.transforms.Increment object at 0x10f2e8250>, 'scores': {'number_of_scored_games': <google.cloud.firestore_v1.transforms.Increment object at 0x10f2e8b50>, 'total_sum': <google.cloud.firestore_v1.transforms.Increment object at 0x10f2e87c0>}, 'potm_count': <google.cloud.firestore_v1.transforms.Increment object at 0x10f2e8be0>, 'record': {'num_win': <google.cloud.firestore_v1.transforms.Increment object at 0x10f2e8b20>, 'num_draw': <google.cloud.firestore_v1.transforms.Increment object at 0x10f2e8700>, 'num_loss': <google.cloud.firestore_v1.transforms.Increment object at 0x10f2e8d60>}, 'last_date_scores': {'20230503143043': 2.5}}

if instead I populate the doc before

db.collection("users").document("user_one").set({"name": "a"})

# some code writing to the db

print(db.collection("users").document("user_one").get().to_dict())

{'name': 'user_one', 'num_matches_joined': 1, 'scores': {'number_of_scored_games': 1, 'total_sum': 2.5}, 'potm_count': 0, 'record': {'num_win': 1, 'num_draw': 0, 'num_loss': 0}, 'last_date_scores': {'20230503143138': 2.5}}

alexlipa91 avatar May 05 '23 14:05 alexlipa91