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

firestore transformations are not supported

Open domanchi opened this issue 4 years ago • 1 comments

Issue

firestore comes with some atomic "transformations" that are used to manipulate data without retrieving the document first, checking the value, then setting it again. These transformations are listed in their documentation: https://googleapis.dev/python/firestore/latest/transforms.html

However, mockfirestore does not support this functionality.

Reproduction Steps

mock_database.collection('user').document('some-random-id').add({'likes': 0})
mock_database.collection('user').document('some-random-id').update({'likes': firestore.Increment(1)})
assert (
    mock_database.collection('user').document('some-random-id').get().to_dict() ==
    {'likes': 1}
)

Instead, I get something like:

{'likes': <google.cloud.firestore_v1.transforms.Increment object at 0x106ee5208>}

domanchi avatar Aug 22 '20 14:08 domanchi

Hi @domanchi. I followed your implementation and added the firestore ArrayUnion transformation, but finally I ended up adding custom transformation classes to the mock library because I think it is better to be decoupled from the firestore python library. The pull request is here #38

RDelg avatar Jan 27 '21 20:01 RDelg