arijeetmukherjee3108-droid opened a new issue, #41679:
URL: https://github.com/apache/beam/issues/41679
### What happened?
**Beam version:** `master` (Python SDK)
In `sdks/python/apache_beam/ml/rag/ingestion/spanner.py`,
`SpannerColumnSpecsBuilder.add_metadata_field()` delegates value extraction and
conversion to `_extract_and_convert()`, which calls `convert_fn`
unconditionally even when the extracted value is `None` (for example, when the
metadata key is missing with the default `default=None`, or explicitly set to
`None`):
```python
def _extract_and_convert(extract_fn, convert_fn, embeddable):
if convert_fn:
return convert_fn(extract_fn(embeddable))
return extract_fn(embeddable)
```
Running the docstring's `created_at` example on an `EmbeddableItem` without
`"created_at"` in `metadata` raises an `AttributeError`:
```python
from apache_beam.ml.rag.ingestion.spanner import SpannerColumnSpecsBuilder
from apache_beam.ml.rag.types import Content, EmbeddableItem
specs = (
SpannerColumnSpecsBuilder()
.add_metadata_field("created_at", str, convert_fn=lambda ts:
ts.isoformat())
.build()
)
specs[0].value_fn(EmbeddableItem(content=Content(text="hello"), id="1",
metadata={}))
# AttributeError: 'NoneType' object has no attribute 'isoformat'
```
Both sibling builders (`mysql_common.py` and `postgres_common.py`) guard
against this with `if value is not None and convert_fn is not None:`.
### Expected Behavior
When the extracted metadata value is `None`, `convert_fn` should be skipped
and `None` returned directly, matching `mysql_common.py` and
`postgres_common.py`.
### Issue Priority
Priority: 2 (default / most bugs should be filed as P2)
### Issue Components
- [x] Component: Python SDK
- [ ] Component: Java SDK
- [ ] Component: Go SDK
- [ ] Component: Typescript SDK
- [x] Component: IO connector
- [ ] Component: Beam YAML
- [ ] Component: Beam examples
- [ ] Component: Beam playground
- [ ] Component: Beam katas
- [ ] Component: Website
- [ ] Component: Infrastructure
- [ ] Component: Spark Runner
- [ ] Component: Flink Runner
- [ ] Component: Prism Runner
- [ ] Component: Hazelcast Jet Runner
- [ ] Component: Google Cloud Dataflow Runner
--
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]