uranusjr commented on code in PR #22679:
URL: https://github.com/apache/airflow/pull/22679#discussion_r843550012


##########
airflow/models/mappedoperator.py:
##########
@@ -677,3 +677,18 @@ def _find_index_for_this_field(index: int) -> int:
             if i == found_index:
                 return k, v
         raise IndexError(f"index {map_index} is over mapped length")
+
+    @cached_property
+    def mapped_args_are_literals(self) -> bool:
+        """Are all the mapped arguments to this class static literals"""
+        expansion_kwargs = self._get_expansion_kwargs()
+
+        return all(isinstance(item, (list, dict)) for item in 
expansion_kwargs.values())
+
+    @cached_property
+    def mapped_args_count(self) -> int:
+        """Count the length of the mapped arguments to this class"""
+        from airflow.models.xcom_arg import XComArg
+
+        expansion_kwargs = self._get_expansion_kwargs()
+        return sum(len(item) for item in expansion_kwargs.values() if not 
isinstance(item, XComArg))

Review Comment:
   This should probably be `literal_mapped_args_count_sum` since it does not 
count XComArg args. Also it may be a good idea to merge this with 
`mapped_args_are_literals`; both these are only called once and we shouldn’t 
need to iterate through the kwargs twice.
   
   I’d do something higher level like
   
   ```python
   def expand_ti_if_only_literal_mapped_args(self):
       expansion_kwargs = self._get_expansion_kwargs()
       literal_counts = [len(item) for item in expansion_kwargs.values() if not 
isinstance(item, XComArg)]
       if len(expansion_kwargs) != len(literal_counts):
           return [-1]  # Has non-literals, don't expand.
       # Move expand_mapped_literals here...
   ```



-- 
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]

Reply via email to