Skip to content
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

Trigger cannot find document when document id contains non-ascii characters #220

Closed
jinminghe950 opened this issue Oct 31, 2024 · 3 comments
Labels
waiting for customer response Issue is on hold awaiting more information from OP

Comments

@jinminghe950
Copy link

My document id:
H67iEkcHx6Nicg5eoZbmxARLyJo2_KoX4bc4jGmTKwSGLI9GBdF46Hbt2_中餐

The last two characters are Chinese characters.

Relavent code:
event.data.after.reference.update()

Error message:
google.api_core.exceptions.NotFound: 404 No document to update: projects/{project_name}/databases/(default)/documents/{collection_name}/H67iEkcHx6Nicg5eoZbmxARLyJo2_KoX4bc4jGmTKwSGLI9GBdF46Hbt2_中�"

@exaby73
Copy link
Contributor

exaby73 commented Oct 31, 2024

Hey @jinminghe950. Could you give me a complete example including which trigger you're using?

@exaby73 exaby73 added the waiting for customer response Issue is on hold awaiting more information from OP label Oct 31, 2024
@jinminghe950
Copy link
Author

Thanks for getting back. PTAL:

@on_document_updated(document="conversations/{doc_id}")
def listen_to_chat(event: Event[Change[DocumentSnapshot | None]]) -> None:
    # Check if the latest message is a user response
    if conversation and conversation[-1].get("role") == "user":
        doc_id = event.params["doc_id"]

        logger.info(f"New user response detected for document {doc_id}")
        messages = [
            {"role": message.get("role"), "content": message.get("content")}
            for message in conversation
        ]
        response = chat_completion(messages)

        # TODO: conversation with Chinese tag ID is still broken.
        event.data.after.reference.update(
            {
                "conversation": firestore.ArrayUnion(
                    [
                        {
                            "role": "assistant",
                            "content": response,
                            "timestamp": datetime.now(),
                        }
                    ]
                )
            }
        )

        logger.info(f"Added response for document {doc_id}")
    else:
        logger.info("No new user response, no action needed.")

The error is from event.data.after.reference.update(), but I didn't manipulate the document id.

@CorieW
Copy link

CorieW commented Dec 30, 2024

I managed to reproduce this and I believe it's an issue with python-firestore, so I've created an issue there.

@CorieW CorieW closed this as completed Dec 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting for customer response Issue is on hold awaiting more information from OP
Projects
None yet
Development

No branches or pull requests

3 participants