Skip to content

Commit 1a937b0

Browse files
andyfangdzhiranya911
authored andcommitted
Remove unnecessary checks on update with etag (#63)
* Remove unnecessary checks on update with etag * Add test of scalar transaction * Add integration test for scalar transactions * bump version
1 parent 99c48ef commit 1a937b0

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

firebase_admin/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
# Declaring module version as per https://www.python.org/dev/peps/pep-0396/#specification
2525
# Update this accordingly for each release.
26-
__version__ = '2.2.0'
26+
__version__ = '2.2.1'
2727

2828
_apps = {}
2929
_apps_lock = threading.RLock()

firebase_admin/db.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,6 @@ def update(self, value):
201201

202202
def _update_with_etag(self, value, etag):
203203
"""Sets the data at this location to the specified value, if the etag matches."""
204-
if not value or not isinstance(value, dict):
205-
raise ValueError('Value argument must be a non-empty dictionary.')
206-
if None in value.keys() or None in value.values():
207-
raise ValueError('Dictionary must not contain None keys or values.')
208204
if not isinstance(etag, six.string_types):
209205
raise ValueError('ETag must be a string.')
210206

integration/test_db.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,15 @@ def transaction_update(snapshot):
178178
assert new_value == expected
179179
assert ref.get() == expected
180180

181+
def test_transaction_scalar(self, testref):
182+
python = testref.parent
183+
ref = python.child('users/count')
184+
ref.set(42)
185+
new_value = ref.transaction(lambda x: x + 1 if x else 1)
186+
expected = 43
187+
assert new_value == expected
188+
assert ref.get() == expected
189+
181190
def test_delete(self, testref):
182191
python = testref.parent
183192
ref = python.child('users').push('foo')

tests/test_db.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,18 @@ def transaction_update(data):
318318
assert recorder[1].method == 'PUT'
319319
assert json.loads(recorder[1].body.decode()) == {'foo1': 'bar1', 'foo2': 'bar2'}
320320

321+
def test_transaction_scalar(self):
322+
ref = db.reference('/test/count')
323+
data = 42
324+
recorder = self.instrument(ref, json.dumps(data))
325+
326+
new_value = ref.transaction(lambda x: x + 1 if x else 1)
327+
assert new_value == 43
328+
assert len(recorder) == 2
329+
assert recorder[0].method == 'GET'
330+
assert recorder[1].method == 'PUT'
331+
assert json.loads(recorder[1].body.decode()) == 43
332+
321333
def test_transaction_error(self):
322334
ref = db.reference('/test')
323335
data = {'foo1': 'bar1'}

0 commit comments

Comments
 (0)