-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
KeyError: 'datacontenttype' #187
Comments
Which version of the library are you using? |
Hey @edump72. Trying something similar, I cannot reproduce this issue. I get an error with the field name you're using: ValueError: Path Oración not consumed, residue: ón Here's the code example I used: from firebase_functions import firestore_fn
@firestore_fn.on_document_created(document='Solicitud desde Android Studio/Entidades')
def on_post_created(event: firestore_fn.Event[firestore_fn.DocumentSnapshot]):
print(event.data)
if event.data is None:
return
try:
event.data.get("Oración")
except KeyError:
return Edit: This is the fill stack trace I get on emulators. Same is applicable for deployed functions as well: Logs> <google.cloud.firestore_v1.base_document.DocumentSnapshot object at 0x1080efc50>
> [2024-04-18 15:37:02,500] ERROR in app: Exception on /functions/projects/ [POST]
> Traceback (most recent call last):
> File "/Users/nabeelparkar/dev/invertase/testing/python-functions/functions/venv/lib/python3.12/site-packages/flask/app.py", line 1473, in wsgi_app
> response = self.full_dispatch_request()
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> File "/Users/nabeelparkar/dev/invertase/testing/python-functions/functions/venv/lib/python3.12/site-packages/flask/app.py", line 882, in full_dispatch_request
> rv = self.handle_user_exception(e)
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> File "/Users/nabeelparkar/dev/invertase/testing/python-functions/functions/venv/lib/python3.12/site-packages/flask/app.py", line 880, in full_dispatch_request
> rv = self.dispatch_request()
> ^^^^^^^^^^^^^^^^^^^^^^^
> File "/Users/nabeelparkar/dev/invertase/testing/python-functions/functions/venv/lib/python3.12/site-packages/flask/app.py", line 865, in dispatch_request
> return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) # type: ignore[no-any-return]
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> File "/Users/nabeelparkar/dev/invertase/testing/python-functions/functions/venv/lib/python3.12/site-packages/functions_framework/__init__.py", line 178, in view_func
> function(event)
> File "/Users/nabeelparkar/dev/invertase/testing/python-functions/functions/venv/lib/python3.12/site-packages/firebase_functions/firestore_fn.py", line 446, in on_document_created_wrapped
> return _firestore_endpoint_handler(
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> File "/Users/nabeelparkar/dev/invertase/testing/python-functions/functions/venv/lib/python3.12/site-packages/firebase_functions/firestore_fn.py", line 217, in _firestore_endpoint_handler
> _typing.cast(_C1 | _C2, func)(database_event)
> File "/Users/nabeelparkar/dev/invertase/testing/python-functions/functions/venv/lib/python3.12/site-packages/firebase_functions/core.py", line 125, in wrapper
> return fn(*args, **kwargs)
> ^^^^^^^^^^^^^^^^^^^
> File "/Users/nabeelparkar/dev/invertase/testing/python-functions/functions/main.py", line 13, in on_post_created
> event.data.get("Oración")
> File "/Users/nabeelparkar/dev/invertase/testing/python-functions/functions/venv/lib/python3.12/site-packages/google/cloud/firestore_v1/base_document.py", line 487, in get
> nested_data = field_path_module.get_nested_value(field_path, self._data)
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> File "/Users/nabeelparkar/dev/invertase/testing/python-functions/functions/venv/lib/python3.12/site-packages/google/cloud/firestore_v1/field_path.py", line 229, in get_nested_value
> field_names = parse_field_path(field_path)
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> File "/Users/nabeelparkar/dev/invertase/testing/python-functions/functions/venv/lib/python3.12/site-packages/google/cloud/firestore_v1/field_path.py", line 121, in parse_field_path
> for field_name in split_field_path(api_repr):
> ^^^^^^^^^^^^^^^^^^^^^^^^^^
> File "/Users/nabeelparkar/dev/invertase/testing/python-functions/functions/venv/lib/python3.12/site-packages/google/cloud/firestore_v1/field_path.py", line 84, in split_field_path
> for element in _tokenize_field_path(path):
> File "/Users/nabeelparkar/dev/invertase/testing/python-functions/functions/venv/lib/python3.12/site-packages/google/cloud/firestore_v1/field_path.py", line 64, in _tokenize_field_path
> raise ValueError("Path {} not consumed, residue: {}".format(path, path[pos:]))
> ValueError: Path Oración not consumed, residue: ón |
Oh....is this an issue of Python and "non-ASCII" characters in field names? Firestore is documented as supporting valid UTF-8 characters in field names, but maybe there's an issue with how Python is dealing with those strings? [I haven't done a lot of Python coding in a long time, but I did suffer somewhat through the non-UTF8 wars of Python 2 vs. 3 ...] |
I believe that is a separate issue and not one with this SDK but rather upstream with the Google Cloud SDK we use internally. But what I don't get is how this error with |
I am creating a Google Cloud Function using a Python script, in order to handle the creation of a new document in my Firestore database. When the data of the new document is fetched, I create an SVG with it using Spacy. I have used the documentation in order to handle this event : https://firebase.google.com/docs/functions/firestore-events?hl=es-419&gen=2nd#python-preview_1
This is my Python script :
I have deployed the function using Google Cloud Console, setting everything correctly. The function is accepted, but when I enter a trigger event:
,my Firestore database continues as it was and I get this error :
Anyone knows what is the problem? Thank you in advance!
The text was updated successfully, but these errors were encountered: