jscheffl commented on code in PR #59999:
URL: https://github.com/apache/airflow/pull/59999#discussion_r2659844654


##########
airflow-core/src/airflow/serialization/helpers.py:
##########
@@ -29,6 +30,33 @@
     from airflow.timetables.base import Timetable as CoreTimetable
 
 
+def truncate_rendered_value(rendered: Union[str, bytes, Sequence], max_length: 
int) -> str:
+    """
+    Truncate rendered value with a reasonable minimum length to avoid edge 
cases.
+    
+    Args:
+        rendered: The rendered value to truncate
+        max_length: The maximum allowed length for the output
+        
+    Returns:
+        Truncated string that respects the max_length constraint
+    """
+    # Set a reasonable minimum to avoid complex edge cases with very small 
values
+    if max_length < 100:
+        max_length = 100
+
+    prefix = "Truncated. You can change this behaviour in 
[core]max_templated_field_length. "
+    suffix = "... "
+    
+    available_length = max_length - len(prefix) - len(suffix)
+    if available_length <= 0:
+        return (prefix + suffix)[:max_length]
+    
+    content_length = max(0, available_length)
+    content_part = rendered[:content_length]
+    return f"{prefix}{repr(content_part)}{suffix}"

Review Comment:
   The wrapping into `repr()` is too late here. That should be done before you 
cut the substring above (in my view).
   ```suggestion
       return f"{prefix}{content_part}{suffix}"
   ```



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