You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2022/10/17 03:18:08 UTC

[GitHub] [airflow] dstandish commented on a diff in pull request #27070: Allow and prefer non-prefixed extra fields for slack hooks

dstandish commented on code in PR #27070:
URL: https://github.com/apache/airflow/pull/27070#discussion_r996579932


##########
airflow/providers/slack/hooks/slack.py:
##########
@@ -28,14 +29,45 @@
 from airflow.compat.functools import cached_property
 from airflow.exceptions import AirflowException, AirflowNotFoundException
 from airflow.hooks.base import BaseHook
-from airflow.providers.slack.utils import ConnectionExtraConfig, prefixed_extra_field
+from airflow.providers.slack.utils import ConnectionExtraConfig
 from airflow.utils.log.secrets_masker import mask_secret
 
 if TYPE_CHECKING:
     from slack_sdk.http_retry import RetryHandler
     from slack_sdk.web.slack_response import SlackResponse
 
 
+def _ensure_prefixes(conn_type):
+    """
+    Remove when provider min airflow version >= 2.5.0 since this is handled by
+    provider manager from that version.
+    """
+
+    def dec(func):
+        def _ensure_prefix_for_placeholders(field_behaviors: dict[str, Any], conn_type: str):
+            conn_attrs = {'host', 'schema', 'login', 'password', 'port', 'extra'}
+
+            def _ensure_prefix(field):
+                if field not in conn_attrs and not field.startswith('extra__'):
+                    return f"extra__{conn_type}__{field}"
+                else:
+                    return field
+
+            if 'placeholders' in field_behaviors:
+                placeholders = field_behaviors['placeholders']
+                field_behaviors['placeholders'] = {_ensure_prefix(k): v for k, v in placeholders.items()}
+
+            return field_behaviors
+
+        @wraps(func)
+        def inner(cls):
+            return _ensure_prefix_for_placeholders(func(cls), conn_type)

Review Comment:
   yup, looks like it :) 



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org