Skip to content

DB pattern matching not working as expected  #113

Closed
@adimaggio2021

Description

@adimaggio2021

I'm writing a function with a realtime DB trigger.

@db_fn.on_value_created(reference="/messages/{user}/{chat_id}/{msg_id}")
def do_work(event: db_fn.Event[Any]) -> None:
    # process event

From reading the docs, I expect this to match on a message pushed to a chat with chat_id. For example, a value created at /messages/user_1/chat_1/msg_a would be captured and the appropriate ids sent to the function.

However, when I attempt to implement this functionality, errors crop up in the pattern matching code:

File "/layers/google.python.pip/pip/lib/python3.11/site-packages/firebase_functions/private/path_pattern.py", line 177, in extract_matches
    matches[segment.trimmed] = path_segments[path_ndx]
                               ~~~~~~~~~~~~~^^^^^^^^^^
IndexError: list index out of range

It seems like the pattern-matching code errors out in this situation where the value created is at a ref with a wildcard in the last path segment. I'm using a workaround right now but thought I'd bring it up as an issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions