Google-cloud-python: Firestore: _tokenize_field_path crashes when subpath starts with number

Created on 21 May 2019  Â·  3Comments  Â·  Source: googleapis/google-cloud-python

Research

  • Search the issues already opened: ✅
  • Check for answers on StackOverflow: ✅

Environment details

  1. Firestore
  2. OS type and version: Docker(python:3.7.3)
  3. Python version and virtual environment information: python:3.7.3
  4. google-cloud- version: google-cloud-firestore==1.2.0

Steps to reproduce

  1. Use .where(f"something.3blah", "==", True) on a collection.

Code example

ref = (
    db.collection("mycollection")
    .where(f"something.3a", "==", True)
)

Stack trace

Traceback (most recent call last):
  File "test.py", line 68, in <module>
    split_field_path('seomthing.3a')
  File "test.py", line 49, in split_field_path
    for element in _tokenize_field_path(path):
  File "test.py", line 30, in _tokenize_field_path
    raise ValueError("Path {} not consumed, residue: {}".format(path, path[pos:]))
ValueError: Path seomthing.3a not consumed, residue: 3a

Have narrowed down the issue to this function: https://github.com/googleapis/google-cloud-python/blob/master/firestore/google/cloud/firestore_v1beta1/field_path.py#L71
Reproducible snippet: (https://gist.github.com/jakebolam/7983326e41672a473365d0d46b643e6f)

question firestore

Most helpful comment

The rules for field paths are a little complicated. You need to escape any path element which is not an "identifier"; e.g., in your case:

ref = (
    db.collection("mycollection")
    .where(f"something.`3a`", "==", True)
)

All 3 comments

Thanks for the report

The rules for field paths are a little complicated. You need to escape any path element which is not an "identifier"; e.g., in your case:

ref = (
    db.collection("mycollection")
    .where(f"something.`3a`", "==", True)
)

Thanks for the speedy response @tseaver. That definitely gets things working. Cheers

Was this page helpful?
0 / 5 - 0 ratings