arijeetmukherjee3108-droid opened a new pull request, #41811:
URL: https://github.com/apache/beam/pull/41811
Fixes #26755
### Problem
When using `WriteToDatastore` or `DeleteFromDatastore` with a
`RuntimeValueProvider` for `project` (e.g., in Dataflow Classic Templates),
pipeline construction fails in `DisplayData` with:
```text
ValueError: Invalid DisplayDataItem. Value RuntimeValueProvider(...) is of
an unsupported type.
```
Additionally, runtime paths (`start_bundle`, `_flush_batch` metrics/resource
labels, and entity/key project fallback) assume `self._project` is already a
`str` rather than resolving a `ValueProvider`.
### Changes
- Support `ValueProvider` (`RuntimeValueProvider` and `StaticValueProvider`)
in addition to `str` for the `project` argument in `WriteToDatastore`,
`DeleteFromDatastore`, and `_Mutate.DatastoreMutateFn` (and updated docstrings).
- Convert `ValueProvider` to `str(self._project)` in
`_DatastoreWriteFn.display_data()` and `_DatastoreDeleteFn.display_data()`.
Using `str()` rather than `.get()` avoids `RuntimeValueProviderError` at
graph/template construction time when the provider is not yet accessible
(matching `bigquery.py`).
- Add `_Mutate.DatastoreMutateFn._get_project()` to resolve `ValueProvider`
via `.get()` at worker runtime in:
- `start_bundle` (`helper.get_client`)
- `_flush_batch` (`resource_identifiers.DatastoreNamespace` and
`DATASTORE_PROJECT_ID_LABEL`)
- `_DatastoreWriteFn.element_to_client_batch_item` and
`_DatastoreDeleteFn.element_to_client_batch_item` (entity/key project fallback)
- Add unit tests in
`sdks/python/apache_beam/io/gcp/datastore/v1new/datastoreio_test.py` covering
`DisplayData` generation (at construction time) and runtime execution with both
`RuntimeValueProvider` and `StaticValueProvider`.
### Testing
- `pytest apache_beam/io/gcp/datastore/v1new/datastoreio_test.py` (23 passed)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]