Skip to content

Error getting field when field name contains Unicode character #1000

Open
@CorieW

Description

@CorieW

Details

An issue was created for this in firebase-functions-python #187, but I believe this is an issue with this project, so I'm creating an issue here.

I recently reported a similar issue, but with document id #999

Environment details

  • OS type and version: Windows 10
  • google-cloud-firestore version: 2.19.0

Steps to reproduce

  1. Create a new firebase project using firebase init
    a. Use Firestore and Functions when prompted
    b. When prompted for language, select Python
  2. Add the code below to main.py in /functions
  3. Use firebase emulators with firebase emulators:start

Code example

from firebase_functions import firestore_fn, https_fn, logger
from firebase_admin import initialize_app, firestore
import google.cloud.firestore

app = initialize_app()

@firestore_fn.on_document_created(document="test/1")
def sentenceToImageFunc(event: firestore_fn.Event[firestore_fn.DocumentSnapshot | None]) -> None:
    logger.info("Received a new document.")
    firestore_client: google.cloud.firestore.Client = firestore.client()
    # Get the value of "Oración" if it exists.
    if event.data is None:
        return
    try:
        sentence = event.data.get("Oración")
        logger.info(f"Processing sentence: {sentence}")
    except KeyError:
        logger.error("Document is missing 'Oración' field.")
        # No "Oración" field, so do nothing.
        return

Stack trace

>  Traceback (most recent call last):
>    File "app\functions\venv\Lib\site-packages\flask\app.py", line 1511, in wsgi_app
>      response = self.full_dispatch_request()
>                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>    File "app\functions\venv\Lib\site-packages\flask\app.py", line 919, in full_dispatch_request
>      rv = self.handle_user_exception(e)
>           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>    File "app\functions\venv\Lib\site-packages\flask\app.py", line 917, in full_dispatch_request
>      rv = self.dispatch_request()
>           ^^^^^^^^^^^^^^^^^^^^^^^
>    File "app\functions\venv\Lib\site-packages\flask\app.py", line 902, in dispatch_request
>      return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)  # type: ignore[no-any-return]
>             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>    File "app\functions\venv\Lib\site-packages\functions_framework\execution_id.py", line 106, in wrapper
>      return view_function(*args, **kwargs)
>             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>    File "app\functions\venv\Lib\site-packages\functions_framework\__init__.py", line 188, in view_func
>      function(event)
>    File "app\functions\venv\Lib\site-packages\firebase_functions\firestore_fn.py", line 451, in on_document_created_wrapped
>      return _firestore_endpoint_handler(
>             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>    File "app\functions\venv\Lib\site-packages\firebase_functions\firestore_fn.py", line 222, in _firestore_endpoint_handler
>      _typing.cast(_C1 | _C2, func)(database_event)
>    File "app\functions\venv\Lib\site-packages\firebase_functions\core.py", line 125, in wrapper
>      return fn(*args, **kwargs)
>             ^^^^^^^^^^^^^^^^^^^
>    File "app\functions\main.py", line 16, in sentenceToImageFunc
>      sentence = event.data.get("Oración")
>                 ^^^^^^^^^^^^^^^^^^^^^^^^^
>    File "app\functions\venv\Lib\site-packages\google\cloud\firestore_v1\base_document.py", line 496, in get
>      nested_data = field_path_module.get_nested_value(field_path, self._data)
>                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>    File "app\functions\venv\Lib\site-packages\google\cloud\firestore_v1\field_path.py", line 227, in get_nested_value
>      field_names = parse_field_path(field_path)
>                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>    File "app\functions\venv\Lib\site-packages\google\cloud\firestore_v1\field_path.py", line 119, in parse_field_path
>      for field_name in split_field_path(api_repr):
>                        ^^^^^^^^^^^^^^^^^^^^^^^^^^
>    File "app\functions\venv\Lib\site-packages\google\cloud\firestore_v1\field_path.py", line 82, in split_field_path
>      for element in _tokenize_field_path(path):
>    File "app\functions\venv\Lib\site-packages\google\cloud\firestore_v1\field_path.py", line 62, in _tokenize_field_path
>      raise ValueError("Path {} not consumed, residue: {}".format(path, path[pos:]))
>  ValueError: Path Oración not consumed, residue: ón

Metadata

Metadata

Assignees

Labels

api: firestoreIssues related to the googleapis/python-firestore API.priority: p3Desirable enhancement or fix. May not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions