1fanwang opened a new pull request, #70338:
URL: https://github.com/apache/airflow/pull/70338

   `message_history` (AgentOperator) and `source_path`/`file_type` 
(DocumentLoaderOperator) are template fields, so they are rendered after 
`__init__` runs. Both constructors validated them there, acting on the 
un-rendered Jinja expressions:
   
   - `AgentOperator` rejected `message_history` combined with 
`enable_hitl_review`. A templated `message_history` (e.g. `"{{ 
ti.xcom_pull(...) }}"`) is a truthy string in `__init__`, so the check fired 
even when it renders to nothing.
   - `DocumentLoaderOperator` enforced the `source_path` / `source_bytes` / 
`file_type` combination, so a templated `source_path` couldn't resolve before 
the mutual-exclusivity check ran.
   
   Move those checks into `execute()`, which runs after rendering. 
Constructor-only checks that read no template field (`durable`/`code_mode`) 
stay in `__init__`.
   
   related: #70296
   
   <details><summary>Testing Done</summary>
   
   Updated the validation tests to drive `execute()`: 
`test_message_history_with_hitl_review_raises` and DocumentLoader's 
`test_both_sources_raises` / `test_neither_source_raises` / 
`test_source_bytes_without_file_type_raises` / 
`test_empty_bytes_without_file_type_raises`. Each fails on the pre-fix source 
(the constructor raises first, before the operator can render) and passes 
after. Full suites: `test_agent.py` + `test_document_loader.py` = 94 passed. 
`validate_operators_init.py` on both operators exits 0.
   
   </details>
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [X] Yes (please specify the tool below)
   
   Generated-by: GitHub Copilot CLI following [the 
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
   


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