Skip to content

Missing "authtype" and "authid" for "on_document_written_with_auth_context" trigger functions in emulators #210

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

Closed
andreas-thomik opened this issue Jul 1, 2024 · 6 comments
Labels
blocked:gcp This is blocked on GCP bug Something isn't working

Comments

@andreas-thomik
Copy link

Pretty much what the title says. The authid and authtype fields are present for all the other on_document_<...>_with_auth_context functions but are missing for on_document_written_with_auth_context

This might be an issue with the emulators themselves, if so please let me know and I'll post it to the relevant issue tracker.

@exaby73
Copy link
Contributor

exaby73 commented Jul 1, 2024

Hello @andreas-thomik. Is this only reproducible with emulators?

@exaby73 exaby73 added the waiting for customer response Issue is on hold awaiting more information from OP label Jul 1, 2024
@andreas-thomik
Copy link
Author

Honestly not tested since #207 makes the _with_auth_context functions useless at the moment but I'll try a minimal setup later tonight and will report back.

@andreas-thomik
Copy link
Author

@exaby73 I can confirm that this happens for both emulators and live functions.

Here's a minimal example to reproduce:

import logging

import firebase_functions.firestore_fn
from firebase_functions.firestore_fn import (
    AuthEvent,
    Change,
    DocumentSnapshot,
    _firestore_endpoint_handler,
    on_document_created_with_auth_context,
    on_document_written_with_auth_context,
)

logger = logging.getLogger()


def _inspect_endpoint_handler(*args, **kwargs):
    logger.warning("Args: %s", args)
    logger.warning("Kwargs: %s", kwargs)

    return _firestore_endpoint_handler(*args, **kwargs)


firebase_functions.firestore_fn._firestore_endpoint_handler = (
    _inspect_endpoint_handler
)


@on_document_written_with_auth_context(document="tests/{docId}")
def test_doc_written(event: AuthEvent[Change[DocumentSnapshot | None]]):
    return event


@on_document_created_with_auth_context(document="tests/{docId}")
def test_doc_created(event: AuthEvent[DocumentSnapshot]):
    return event

The actual parameters sent to _firestore_endpoint_handler can be seen in the logs, here's a (slightly redacted) copy of mine:

Logs for on_document_written_with_auth_context

{
  "attributes": {
    "specversion": "1.0", 
    "id": "...", 
    "source": "//firestore.googleapis.com/projects/MY-PROJECT/databases/(default)", 
    "type": "google.cloud.firestore.document.v1.written", 
    "datacontenttype": "application/protobuf", 
    "dataschema": "https://github.com/googleapis/google-cloudevents/blob/main/proto/google/events/cloud/firestore/v1/data.proto", 
    "subject": "documents/tests/LmbRywPwqsWgVJmG4JNe", 
    "time": "2024-07-01T19:24:45.860351Z", 
    "namespace": "(default)", 
    "document": "tests/LmbRywPwqsWgVJmG4JNe", 
    "location": "europe-west6", 
    "database": "(default)", 
    "project": "MY-PROJECT"
  }, 
  "data": "..."
}

Compare this with the logs for on_document_created_with_auth_context:

{
  "attributes": {
    "specversion": "1.0",
    "id": "...",
    "source": "//firestore.googleapis.com/projects/MY-PROJECT/databases/(default)",
    "type": "google.cloud.firestore.document.v1.created.withAuthContext",
    "datacontenttype": "application/protobuf",
    "dataschema": "https://github.com/googleapis/google-cloudevents/blob/main/proto/google/events/cloud/firestore/v1/data.proto", 
    "subject": "documents/tests/LmbRywPwqsWgVJmG4JNe", 
    "time": "2024-07-01T19:24:45.860351Z", 
    "location": "europe-west6", 
    "namespace": "(default)", 
    "document": "tests/LmbRywPwqsWgVJmG4JNe", 
    "authtype": "unknown", 
    "project": "MY-PROJECT", 
    "database": "(default)", 
    "authid": "MY-EMAIL"
  }, 
  "data": "..."
}

@exaby73
Copy link
Contributor

exaby73 commented Jul 3, 2024

This seems to be an upstream issue. I've raised this forward. I'll get back to you soon on an update on this issue

@exaby73
Copy link
Contributor

exaby73 commented Jul 3, 2024

For context, seems to be a similar issue on the Node SDK as well (firebase/firebase-functions#1582)

@exaby73 exaby73 added bug Something isn't working blocked:gcp This is blocked on GCP and removed waiting for customer response Issue is on hold awaiting more information from OP labels Jul 3, 2024
@exaby73
Copy link
Contributor

exaby73 commented Jul 15, 2024

Should be fixed by #214 and a release should go out soon

@exaby73 exaby73 closed this as completed Jul 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked:gcp This is blocked on GCP bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants