Note
Currently Stackdriver's monitoring-related operators are being renamed to Cloud Monitoring in #73354.
You may independently implement the fix in Stackdriver's implementation, and I'll get it merged to #73354 before the latter is being merged.
Summary
Make the Cloud Monitoring list operators preserve the hook output when format_ is explicitly set. Currently, format_="dict" and format_="json" both fail with a TypeError.
Background
CloudMonitoringHook.list_alert_policies() and list_notification_channels() already honor format_: "dict" returns dictionaries, "json" returns JSON strings, and None returns protobuf objects. The corresponding operators then unconditionally call AlertPolicy.to_dict() or NotificationChannel.to_dict() on every result. That conversion only accepts protobuf objects, so passing an already-converted dictionary or JSON string raises TypeError.
The operators should return the hook result unchanged when format_ is set. With format_=None, they should continue converting protobuf objects to dictionaries so the value remains XCom-serializable. Update the operator-level format_ documentation to describe this behavior.
Where to look
providers/google/src/airflow/providers/google/cloud/operators/cloud_monitoring.py — CloudMonitoringListAlertPoliciesOperator.execute and CloudMonitoringListNotificationChannelsOperator.execute.
providers/google/src/airflow/providers/google/cloud/hooks/cloud_monitoring.py — the existing return-format behavior.
providers/google/tests/unit/google/cloud/operators/test_cloud_monitoring.py — unit tests for both operators.
Acceptance criteria
Estimated effort
About 1–2 hours for someone new to the codebase.
Getting started
See Apache Airflow’s contributor quick start.
This issue was drafted with AI assistance and reviewed by a maintainer before filing.
Note
Currently Stackdriver's monitoring-related operators are being renamed to Cloud Monitoring in #73354.
You may independently implement the fix in Stackdriver's implementation, and I'll get it merged to #73354 before the latter is being merged.
Summary
Make the Cloud Monitoring list operators preserve the hook output when
format_is explicitly set. Currently,format_="dict"andformat_="json"both fail with aTypeError.Background
CloudMonitoringHook.list_alert_policies()andlist_notification_channels()already honorformat_:"dict"returns dictionaries,"json"returns JSON strings, andNonereturns protobuf objects. The corresponding operators then unconditionally callAlertPolicy.to_dict()orNotificationChannel.to_dict()on every result. That conversion only accepts protobuf objects, so passing an already-converted dictionary or JSON string raisesTypeError.The operators should return the hook result unchanged when
format_is set. Withformat_=None, they should continue converting protobuf objects to dictionaries so the value remains XCom-serializable. Update the operator-levelformat_documentation to describe this behavior.Where to look
providers/google/src/airflow/providers/google/cloud/operators/cloud_monitoring.py—CloudMonitoringListAlertPoliciesOperator.executeandCloudMonitoringListNotificationChannelsOperator.execute.providers/google/src/airflow/providers/google/cloud/hooks/cloud_monitoring.py— the existing return-format behavior.providers/google/tests/unit/google/cloud/operators/test_cloud_monitoring.py— unit tests for both operators.Acceptance criteria
format_="dict".format_="json".format_, both operators still convert protobuf objects to dictionaries for XCom serialization.format_parameter documentation to accurately state the returned type.Estimated effort
About 1–2 hours for someone new to the codebase.
Getting started
See Apache Airflow’s contributor quick start.
This issue was drafted with AI assistance and reviewed by a maintainer before filing.