Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3b7595b

Browse filesBrowse files
fix: client-side path validation for batch.update (#1021)
1 parent 995fad6 commit 3b7595b
Copy full SHA for 3b7595b

File tree

Expand file treeCollapse file tree

2 files changed

+42
-4
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+42
-4
lines changed

‎google/cloud/firestore_v1/field_path.py

Copy file name to clipboardExpand all lines: google/cloud/firestore_v1/field_path.py
+2-4Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
_ESCAPED_BACKTICK = _BACKSLASH + _BACKTICK
3232

3333
_SIMPLE_FIELD_NAME = re.compile("^[_a-zA-Z][_a-zA-Z0-9]*$")
34-
_LEADING_ALPHA_INVALID = re.compile("^[_a-zA-Z][_a-zA-Z0-9]*[^_a-zA-Z0-9]")
34+
_LEADING_ALPHA_INVALID = re.compile(r"^[_a-zA-Z][_a-zA-Z0-9]*[~*/\[\]]")
3535
PATH_ELEMENT_TOKENS = [
3636
("SIMPLE", r"[_a-zA-Z][_a-zA-Z0-9]*"), # unquoted elements
3737
("QUOTED", r"`(?:\\`|[^`])*?`"), # quoted elements, unquoted
@@ -311,9 +311,7 @@ def from_string(cls, path_string: str):
311311
raise ValueError("Empty element")
312312
if _LEADING_ALPHA_INVALID.match(element):
313313
raise ValueError(
314-
"Non-alphanum char in element with leading alpha: {}".format(
315-
element
316-
)
314+
"Invalid char in element with leading alpha: {}".format(element)
317315
)
318316
return FieldPath(*elements)
319317

‎tests/system/test_system.py

Copy file name to clipboardExpand all lines: tests/system/test_system.py
+40Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3151,6 +3151,28 @@ def in_transaction(transaction):
31513151
assert inner_fn_ran is True
31523152

31533153

3154+
@pytest.mark.parametrize("database", [None, FIRESTORE_OTHER_DB], indirect=True)
3155+
def test_transaction_w_uuid(client, cleanup, database):
3156+
"""
3157+
https://github.com/googleapis/python-firestore/issues/1012
3158+
"""
3159+
collection_id = "uuid_collection" + UNIQUE_RESOURCE_ID
3160+
doc_ref = client.document(collection_id, "doc")
3161+
cleanup(doc_ref.delete)
3162+
key = "b7992822-eacb-40be-8af6-559b9e2fb0b7"
3163+
doc_ref.create({key: "I'm a UUID!"})
3164+
3165+
@firestore.transactional
3166+
def update_doc(tx, doc_ref, key, value):
3167+
tx.update(doc_ref, {key: value})
3168+
3169+
expected = "UPDATED VALUE"
3170+
update_doc(client.transaction(), doc_ref, key, expected)
3171+
# read updated doc
3172+
snapshot = doc_ref.get()
3173+
assert snapshot.to_dict()[key] == expected
3174+
3175+
31543176
@pytest.mark.skipif(
31553177
FIRESTORE_EMULATOR, reason="Query profile not supported in emulator."
31563178
)
@@ -3206,6 +3228,24 @@ def in_transaction(transaction):
32063228
assert inner_fn_ran is True
32073229

32083230

3231+
@pytest.mark.parametrize("database", [None, FIRESTORE_OTHER_DB], indirect=True)
3232+
def test_update_w_uuid(client, cleanup, database):
3233+
"""
3234+
https://github.com/googleapis/python-firestore/issues/1012
3235+
"""
3236+
collection_id = "uuid_collection" + UNIQUE_RESOURCE_ID
3237+
doc_ref = client.document(collection_id, "doc")
3238+
cleanup(doc_ref.delete)
3239+
key = "b7992822-eacb-40be-8af6-559b9e2fb0b7"
3240+
doc_ref.create({key: "I'm a UUID!"})
3241+
3242+
expected = "UPDATED VALUE"
3243+
doc_ref.update({key: expected})
3244+
# read updated doc
3245+
snapshot = doc_ref.get()
3246+
assert snapshot.to_dict()[key] == expected
3247+
3248+
32093249
@pytest.mark.parametrize("with_rollback,expected", [(True, 2), (False, 3)])
32103250
@pytest.mark.parametrize("database", [None, FIRESTORE_OTHER_DB], indirect=True)
32113251
def test_transaction_rollback(client, cleanup, database, with_rollback, expected):

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.