Taragolis commented on code in PR #27823:
URL: https://github.com/apache/airflow/pull/27823#discussion_r1029015437
##########
airflow/providers/amazon/aws/hooks/base_aws.py:
##########
@@ -405,9 +411,68 @@ def __init__(
self.resource_type = resource_type
self._region_name = region_name
- self._config = config
+ self._config = config or botocore.config.Config()
self._verify = verify
+ @classmethod
+ def _get_provider_version(cls) -> str:
+ """Checks the Providers Manager for the package version."""
+ manager = ProvidersManager()
+ provider_name = manager.hooks[cls.conn_type].package_name # type:
ignore[union-attr]
+ provider = manager.providers[provider_name]
+ return provider.version
+
+ @staticmethod
+ def _find_class_name(target_function_name: str) -> str:
+ """
+ Given a frame off the stack, return the name of the class which made
the call.
+ Note: This method may raise a ValueError or an IndexError, but the
calling
+ method is catching and handling those.
+ """
+ stack = inspect.stack()
+ # Find the index of the most recent frame which called the provided
function name.
+ target_frame_index = [frame.function for frame in
stack].index(target_function_name)
+ # Pull that frame off the stack.
+ target_frame = stack[target_frame_index][0]
+ # Get the local variables for that frame.
+ frame_variables = target_frame.f_locals["self"]
+ # Get the class object for that frame.
+ frame_class_object = frame_variables.__class__
+ # Return the name of the class object.
+ return frame_class_object.__name__
+
+ def _get_caller(self, target_function_name: str = "execute") -> str:
+ """Given a function name, walk the stack and return the name of the
class which called it last."""
+ try:
+ caller = self._find_class_name(target_function_name)
+ if caller == "BaseSensorOperator":
+ # If the result is a BaseSensorOperator, then look for
whatever last called "poke".
+ return self._get_caller("poke")
+ return caller
+ except Exception:
+ # While it is generally considered poor form to catch "Exception",
under
+ # no condition should an error here ever cause an issue for the
user.
+ return "Unknown"
+
+ @staticmethod
+ def _generate_dag_key():
+ dag_id = os.getenv("AIRFLOW_CTX_DAG_ID", "default_dag_id")
+ # The Object Identifier (OID) namespace is used to salt the dag_id
value.
+ # That salted value is used to generate a SHA-1 hash which, by
definition,
+ # can not (reasonably) be reversed. No personal data can be inferred
or
+ # extracted from the resulting UUID.
+ return str(uuid.uuid5(uuid.NAMESPACE_OID, dag_id))
Review Comment:
Just an idea, might if it run DAG_ID context not set then return NIL UUID
`00000000-0000-0000-0000-000000000000`?
--
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]