imrichardwu opened a new pull request, #61878:
URL: https://github.com/apache/airflow/pull/61878

   This pull request introduces a new, consistent truncation helper for 
serializing long template fields, ensuring that users always see a clear 
truncation message and quoted content (when space allows), and applies this 
logic across both the Airflow core and task SDK codebases. Comprehensive unit 
tests are also added to verify the new truncation behavior.
   
   **Truncation logic improvements:**
   
   * Added a new `_truncate_rendered_value` helper function in both 
`airflow/serialization/helpers.py` and 
`airflow/sdk/execution_time/task_runner.py` to consistently handle truncation 
of serialized template fields, prioritizing a clear truncation message and 
preserving quotes around content where appropriate. 
(`airflow-core/src/airflow/serialization/helpers.py` 
[[1]](diffhunk://#diff-208ad60f53c30e39ca40559db277c2aca9ab92fe20b34afa4fc71c5518390720R34-R121)
 `task-sdk/src/airflow/sdk/execution_time/task_runner.py` 
[[2]](diffhunk://#diff-5bef10ab2956abf7360dbf9b509b6e1113407874d24abcc1b276475051f13abfR919-R1006)
   * Updated the serialization logic in both codebases to use 
`_safe_truncate_rendered_value`, replacing the previous ad-hoc truncation logic 
for template fields. (`airflow-core/src/airflow/serialization/helpers.py` 
[[1]](diffhunk://#diff-208ad60f53c30e39ca40559db277c2aca9ab92fe20b34afa4fc71c5518390720L86-R174)
 
[[2]](diffhunk://#diff-208ad60f53c30e39ca40559db277c2aca9ab92fe20b34afa4fc71c5518390720L103-R188);
 `task-sdk/src/airflow/sdk/execution_time/task_runner.py` 
[[3]](diffhunk://#diff-5bef10ab2956abf7360dbf9b509b6e1113407874d24abcc1b276475051f13abfL980-R1068)
 
[[4]](diffhunk://#diff-5bef10ab2956abf7360dbf9b509b6e1113407874d24abcc1b276475051f13abfL997-R1082)
   
   **Testing and validation:**
   
   * Added a new unit test module `test_helpers.py` to thoroughly test the 
truncation helper, covering edge cases such as very small `max_length` values, 
quoted content, and exact output expectations. 
(`airflow-core/tests/unit/serialization/test_helpers.py` 
[airflow-core/tests/unit/serialization/test_helpers.pyR1-R136](diffhunk://#diff-51463bb3e8dd265adcc7c6c9de7d74c1743c3e3d38575aa4924869ff7bb0664dR1-R136))…n
 template fields
   
   Added a new function to truncate rendered values based on a specified 
maximum length, ensuring that truncation messages are prioritized. This 
functionality is integrated into the serialization of template fields, 
enhancing the handling of long strings in the system.
   
   <!--
   Thank you for contributing!
   
   Please provide above a brief description of the changes made in this pull 
request.
   Write a good git commit message following this guide: 
http://chris.beams.io/posts/git-commit/
   
   Please make sure that your code changes are covered with tests.
   And in case of new features or big changes remember to adjust the 
documentation.
   
   Feel free to ping (in general) for the review if you do not see reaction for 
a few days
   (72 Hours is the minimum reaction time you can expect from volunteers) - we 
sometimes miss notifications.
   
   In case of an existing issue, reference it using one of the following:
   
   * closes: #ISSUE
   * related: #ISSUE
   -->
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   <!--
   If generative AI tooling has been used in the process of authoring this PR, 
please
   change below checkbox to `[X]` followed by the name of the tool, uncomment 
the "Generated-by".
   -->
   
   - [x] Yes (please specify the tool below)
   - Used ChatGPT to help create and edit my test cases that were mentioned by 
a reviewer in a closed pr.
   
   <!--
   Generated-by: [Tool Name] following [the 
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
   -->
   
   ---
   
   * Read the **[Pull Request 
Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)**
 for more information. Note: commit author/co-author name and email in commits 
become permanently public when merged.
   * For fundamental code changes, an Airflow Improvement Proposal 
([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals))
 is needed.
   * When adding dependency, check compliance with the [ASF 3rd Party License 
Policy](https://www.apache.org/legal/resolved.html#category-x).
   * For significant user-facing changes create newsfragment: 
`{pr_number}.significant.rst` or `{issue_number}.significant.rst`, in 
[airflow-core/newsfragments](https://github.com/apache/airflow/tree/main/airflow-core/newsfragments).
   


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