This is an automated email from the ASF dual-hosted git repository.

yhu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/beam.git


The following commit(s) were added to refs/heads/master by this push:
     new 0e47f80865e Deprecate Python native SpannerIO, with exposed bug fix 
(#35859)
0e47f80865e is described below

commit 0e47f80865e038f3fb3cc53c09e8b607c072cf52
Author: Yi Hu <[email protected]>
AuthorDate: Wed Aug 13 14:05:35 2025 -0400

    Deprecate Python native SpannerIO, with exposed bug fix (#35859)
    
    * Deprecate native SpannerIO, with exposed bug fix
    
    Fix SpannerIO TypeError due to monitoring_info
    
    Also fix monitoring info error format string
    
    * Update sdks/python/apache_beam/metrics/monitoring_infos.py
    
    Co-authored-by: gemini-code-assist[bot] 
<176961590+gemini-code-assist[bot]@users.noreply.github.com>
    
    * add CHANGES.md
    
    ---------
    
    Co-authored-by: gemini-code-assist[bot] 
<176961590+gemini-code-assist[bot]@users.noreply.github.com>
---
 CHANGES.md                                               |  2 ++
 sdks/python/apache_beam/io/gcp/experimental/spannerio.py | 12 ++++++++----
 sdks/python/apache_beam/metrics/monitoring_infos.py      |  4 ++--
 3 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/CHANGES.md b/CHANGES.md
index ac12203b3d6..db88b8c7980 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -90,6 +90,8 @@
 ## Deprecations
 
 * X behavior is deprecated and will be removed in X versions 
([#X](https://github.com/apache/beam/issues/X)).
+* Python SDK native SpannerIO (apache_beam/io/gcp/experimental/spannerio) is 
deprecated. Use cross-language wrapper
+  (apache_beam/io/gcp/spanner) instead (Python) 
([#35860](https://github.com/apache/beam/issues/35860)).
 
 ## Bugfixes
 
diff --git a/sdks/python/apache_beam/io/gcp/experimental/spannerio.py 
b/sdks/python/apache_beam/io/gcp/experimental/spannerio.py
index 7b615e223cf..cac66bd2ef5 100644
--- a/sdks/python/apache_beam/io/gcp/experimental/spannerio.py
+++ b/sdks/python/apache_beam/io/gcp/experimental/spannerio.py
@@ -17,7 +17,7 @@
 
 """Google Cloud Spanner IO
 
-Experimental; no backwards-compatibility guarantees.
+Deprecated; use apache_beam.io.gcp.spanner module instead.
 
 This is an experimental module for reading and writing data from Google Cloud
 Spanner. Visit: https://cloud.google.com/spanner for more details.
@@ -190,6 +190,7 @@ from apache_beam.transforms import window
 from apache_beam.transforms.display import DisplayDataItem
 from apache_beam.typehints import with_input_types
 from apache_beam.typehints import with_output_types
+from apache_beam.utils.annotations import deprecated
 
 # Protect against environments where spanner library is not available.
 # pylint: disable=wrong-import-order, wrong-import-position, ungrouped-imports
@@ -356,8 +357,8 @@ class _NaiveSpannerReadDoFn(DoFn):
     labels = {
         **self.base_labels,
         monitoring_infos.RESOURCE_LABEL: resource,
-        monitoring_infos.SPANNER_TABLE_ID: table_id
     }
+    if table_id: labels[monitoring_infos.SPANNER_TABLE_ID] = table_id
     service_call_metric = ServiceCallMetric(
         request_count_urn=monitoring_infos.API_REQUEST_COUNT_URN,
         base_labels=labels)
@@ -612,8 +613,8 @@ class _ReadFromPartitionFn(DoFn):
     labels = {
         **self.base_labels,
         monitoring_infos.RESOURCE_LABEL: resource,
-        monitoring_infos.SPANNER_TABLE_ID: table_id
     }
+    if table_id: labels[monitoring_infos.SPANNER_TABLE_ID] = table_id
     service_call_metric = ServiceCallMetric(
         request_count_urn=monitoring_infos.API_REQUEST_COUNT_URN,
         base_labels=labels)
@@ -675,6 +676,7 @@ class _ReadFromPartitionFn(DoFn):
       self._snapshot.close()
 
 
+@deprecated(since='2.68', current='apache_beam.io.gcp.spanner.ReadFromSpanner')
 class ReadFromSpanner(PTransform):
   """
   A PTransform to perform reads from cloud spanner.
@@ -825,6 +827,8 @@ class ReadFromSpanner(PTransform):
     return res
 
 
+@deprecated(
+    since='2.68', current='apache_beam.io.gcp.spanner.WriteToSpannerSchema')
 class WriteToSpanner(PTransform):
   def __init__(
       self,
@@ -1224,8 +1228,8 @@ class _WriteToSpannerDoFn(DoFn):
     labels = {
         **self.base_labels,
         monitoring_infos.RESOURCE_LABEL: resource,
-        monitoring_infos.SPANNER_TABLE_ID: table_id
     }
+    if table_id: labels[monitoring_infos.SPANNER_TABLE_ID] = table_id
     service_call_metric = ServiceCallMetric(
         request_count_urn=monitoring_infos.API_REQUEST_COUNT_URN,
         base_labels=labels)
diff --git a/sdks/python/apache_beam/metrics/monitoring_infos.py 
b/sdks/python/apache_beam/metrics/monitoring_infos.py
index 6dc4b7ef9c5..46f856676d3 100644
--- a/sdks/python/apache_beam/metrics/monitoring_infos.py
+++ b/sdks/python/apache_beam/metrics/monitoring_infos.py
@@ -367,8 +367,8 @@ def create_monitoring_info(
         urn=urn, type=type_urn, labels=labels or {}, payload=payload)
   except TypeError as e:
     raise RuntimeError(
-        f'Failed to create MonitoringInfo for urn {urn} type {type} labels ' +
-        '{labels} and payload {payload}') from e
+        f'Failed to create MonitoringInfo for urn {urn} type {type_urn} '
+        f'labels {labels} and payload {payload}') from e
 
 
 def is_counter(monitoring_info_proto):

Reply via email to