Zhnz opened a new issue, #74018:
URL: https://github.com/apache/airflow/issues/74018

   ### Under which category would you file this issue?
   
   Airflow Core
   
   ### Apache Airflow version
   
   3.3.2
   
   ### What happened and how to reproduce it?
   
   **Issue description**
   The Airflow UI seems to have issues rendering string XCom values when 
newlines are involved.
   In my usecase I have a task that returns a single string containing multiple 
lines (dry-run result for a file deletion job). The content of the xcom value 
in the airflow database is the following:
   
   > "Delete: /mnt/x/y/z/data/test.gdb\nDelete: 
/mnt/x/y/z/data/test2.gdb\nDelete: /mnt/x/y/z/data/test3.gdb\nDelete: 
/mnt/x/y/z/data/test.gdb\nDelete: /mnt/x/y/z/data/test2.gdb\nDelete: 
/mnt/x/y/z/data/test3.gdb\nDelete: /mnt/x/y/z/data/test.gdb\nDelete: 
/mnt/x/y/z/data/test2.gdb\nDelete: /mnt/x/y/z/data/test3.gdb\nDelete: 
/mnt/x/y/z/data/test.gdb\nDelete: /mnt/x/y/z/data/test2.gdb\nDelete: 
/mnt/x/y/z/data/test3.gdb"
   
   When viewing the logged return value of the task, the newlines are shown 
correctly with one "Delete: ..." entry per line:
   
   <img width="618" height="221" alt="Image" 
src="https://github.com/user-attachments/assets/cd6d62f8-2c9a-4285-96da-482cf3b04f9f";
 />
   
   When inside the edit view of the XCom entry, the newlines are also rendered 
correctly:
   
   <img width="660" height="444" alt="Image" 
src="https://github.com/user-attachments/assets/505faae1-87e6-4bd0-9447-5ed189a2f16e";
 />
   
   However, viewing the Xcom value in the Storage->XCom tab, the newlines are 
replaced by spaces:
   
   <img width="1380" height="289" alt="Image" 
src="https://github.com/user-attachments/assets/a84cb38b-dcc3-43d5-ac09-eca881e7cff8";
 />
   
   Also, putting the string into a HITLOperator body breaks the Required 
Actions view:
   
   <img width="1375" height="399" alt="Image" 
src="https://github.com/user-attachments/assets/b1c213fe-cc8c-4fa7-b9f7-b960b47d439f";
 />
   
   The text breaks out of the box containing the body when encountering the 
first "\n". Also just as in the XCom tab, the newlines are replaced by spaces.
   The ApprovalOperator seen in the screenshot is defined as follows:
   ```
       wait_for_confirmation = ApprovalOperator(
           task_id="wait_for_confirmation",
           subject="Sollen die folgenden Operationen durchgeführt werden?",
           body="""
           [Dry-Run Ergebnis]
           {{ ti.xcom_pull(task_ids='dry_run') }}
           """,
           response_timeout=datetime.timedelta(minutes=10),
           defaults=ApprovalOperator.REJECT)
   ```
   
   **Steps to reproduce**
   1. Create a DAG with two tasks: task1->task2
   2. task1 returns a multi-line string (pushed to XCom)
   3. task2 is an ApprovalOperator with a templated body containing the XCom 
result of task1
   4. Run DAG
   5. Observe broken XCom view and HITL-Operator body
   
   ### What you think should happen instead?
   
   - The body of a HITLOperator should stay contained inside the intended 
container for it
   - Newlines in an XCom value should be rendered as such inside the 
HITLOperator body
   - It can be argued about whether multi-line values inside the XCom tab 
should be rendered as a single line or not, because of space constraints. In my 
opinion XCom values should be rendered as-is, so with newlines. If the value 
exceeds a specific number of lines, it makes sense for it to be truncated.
   
   ### Operating System
   
   Debian 12 (bookworm)
   
   ### Deployment
   
   Official Apache Airflow Helm Chart
   
   ### Apache Airflow Provider(s)
   
   _No response_
   
   ### Versions of Apache Airflow Providers
   
   _No response_
   
   ### Official Helm Chart version
   
   Not Applicable
   
   ### Kubernetes Version
   
   Not Applicable
   
   ### Helm Chart configuration
   
   Not Applicable
   
   ### Docker Image customizations
   
   Added the following packages:
   
   ```
   petl
   openpyxl
   requests
   chardet>=3.0.2,<6
   psycopg2-binary
   statsd
   apache-airflow-providers-celery
   apache-airflow-providers-standard
   apache-airflow-providers-postgres
   apache-airflow-providers-fab>=3.7.3
   apache-airflow-providers-opensearch==1.12.1
   asyncpg
   python-ldap
   authlib
   ```
   
   ### Anything else?
   
   Let me know if this issue potentially describes two different issues. I 
would then close it and create two seperate issues regarding the HITLOperator 
body and the XCom tab.
   
   ### Are you willing to submit PR?
   
   - [ ] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [x] I agree to follow this project's [Code of 
Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)
   


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