Skip to content

[DRAFT] feat(firestore): add DML support to pipelines#16473

Draft
daniel-sanche wants to merge 1 commit intomainfrom
firestore_pipelines_dml
Draft

[DRAFT] feat(firestore): add DML support to pipelines#16473
daniel-sanche wants to merge 1 commit intomainfrom
firestore_pipelines_dml

Conversation

@daniel-sanche
Copy link
Copy Markdown
Contributor

WIP

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces delete and update stages to the Firestore pipeline, enabling document deletion and in-place updates. The changes include new stage implementations, pipeline methods, and comprehensive system tests. Feedback highlights a logic error in the test assertions where empty documents were incorrectly identified as deleted, and suggests clarifying the update method's documentation to distinguish between partial updates and full document saves. Additionally, a more explicit syntax for field transformations in YAML tests was recommended for better consistency.

for doc_path, expected_content in expected_state.items():
doc_ref = client.document(doc_path)
snapshot = doc_ref.get()
if expected_content is None or expected_content == {}:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The condition or expected_content == {} could lead to incorrect test failures. An empty document is a valid state in Firestore (snapshot.exists would be true), but this logic treats it as a deleted document. To correctly test for document deletion, the check should only be for expected_content is None, which corresponds to null in the YAML file.

Suggested change
if expected_content is None or expected_content == {}:
if expected_content is None:

for doc_path, expected_content in expected_state.items():
doc_ref = async_client.document(doc_path)
snapshot = await doc_ref.get()
if expected_content is None or expected_content == {}:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Similar to the synchronous test, this condition or expected_content == {} could lead to incorrect test failures. An empty document is a valid state, but this logic treats it as deleted. The check for deletion should likely only be against None.

Suggested change
if expected_content is None or expected_content == {}:
if expected_content is None:

Comment on lines +632 to +635
Updates the documents with the given transformations.

This method updates the documents in place based on the data flowing through the pipeline.
To specify transformations, use `*transformed_fields`.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The current docstring can be confusing as it doesn't clearly distinguish between calling update() with and without arguments. This can make it hard to understand the behavior in different scenarios, like in Example 1. Clarifying the two modes of operation (partial update vs. full document save) would improve usability.

Suggested change
Updates the documents with the given transformations.
This method updates the documents in place based on the data flowing through the pipeline.
To specify transformations, use `*transformed_fields`.
Updates documents in the collection.
When called with *transformed_fields, this method applies partial updates
to documents. When called without arguments, it saves the documents as they
exist in the pipeline stream, overwriting existing documents. This is useful
for persisting changes from previous stages like add_fields or remove_fields.

- description: "Basic DML update"
pipeline:
- Collection: dml_update_coll
- Update: Field.of("status").set("active")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The expression Field.of("status").set("active") is a bit ambiguous. It's not clear if set() is a standard operation on a Field expression or a custom test helper. For setting a field to a constant value, using Constant.of("active").as_("status") would be more explicit and align better with the expression patterns seen in unit tests. This would improve the clarity and maintainability of the test.

      - Update: Constant.of("active").as_("status")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant