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

   `topic` is a template field, so it is rendered after `__init__` runs. The 
presence check `if not (self.topic and self.producer_function)` ran in the 
constructor, where a templated `topic` is still the un-rendered Jinja 
expression (always truthy). A `topic` that renders to empty therefore slipped 
past the guard, and `execute()` tried to produce to it. Move the check to the 
start of `execute()`, which runs after rendering.
   
   related: #70296
   
   <details><summary>Testing Done</summary>
   
   Operator-level repro (real Dag, real render, real `execute`): a templated 
`topic` rendering to `""` reaches the producer on the pre-fix code (message 
delivery is attempted and times out) instead of being rejected. After the fix, 
`execute()` raises up front:
   
   ```
   AirflowException: topic and producer_function must be provided. Got topic= 
and producer_function=...
   ```
   
   The new `test_execute_rejects_empty_rendered_topic` drives that 
render→execute path; it fails on the pre-fix source and passes after. 
`test_produce.py`: 3 passed.
   
   </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