o-nikolas commented on code in PR #34381:
URL: https://github.com/apache/airflow/pull/34381#discussion_r1326472980
##########
airflow/providers/amazon/aws/hooks/base_aws.py:
##########
@@ -493,22 +493,44 @@ def _find_class_name(target_function_name: str) -> str:
stack = inspect.stack()
# Find the index of the most recent frame which called the provided
function name
# and pull that frame off the stack.
- target_frame = next(frame for frame in stack if frame.function ==
target_function_name)[0]
+ target_frames = [frame for frame in stack if frame.function ==
target_function_name]
+ if target_frames:
+ target_frame = target_frames[0][0]
+ else:
+ return None
# 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__
+ @staticmethod
+ def _find_executor_class_name() -> str | None:
+ """Inspect the call stack looking for any executor classes and
returning the first found."""
+ stack = inspect.stack()
+ # Fetch class objects on all frames, looking for one containing an
executor (since it
+ # will inherit from BaseExecutor)
+ for frame in stack:
+ classes = []
+ for name, obj in frame[0].f_globals.items():
+ if inspect.isclass(obj):
+ classes.append(name)
+ if "BaseExecutor" in classes:
+ return classes[-1]
+ return None
+
@return_on_error("Unknown")
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."""
- caller = self._find_class_name(target_function_name)
+ """Try to determine the caller of this hook. Whether that be an AWS
Operator, Sensor or Executor."""
+ caller = self._find_operator_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
+ caller = self._find_operator_class_name("poke")
+ if not caller:
+ # Check if we can find an executor
+ caller = self._find_executor_class_name()
Review Comment:
Updates to boto user agent tagging so that we know which ECS calls come from
the ECS executor.
This code is shared by existing user code/workflows. Careful review here
would be great!
--
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]