Skip to content

Validate ProduceToTopicOperator topic after rendering - #70333

Merged
shahar1 merged 6 commits into
apache:mainfrom
1fanwang:fix-kafka-produce-init
Jul 25, 2026
Merged

Validate ProduceToTopicOperator topic after rendering#70333
shahar1 merged 6 commits into
apache:mainfrom
1fanwang:fix-kafka-produce-init

Conversation

@1fanwang

@1fanwang 1fanwang commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

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

Testing Done

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.


Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

Generated-by: GitHub Copilot CLI following the guidelines

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. 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: apache#70296
Signed-off-by: 1fanwang <1fannnw@gmail.com>
@1fanwang
1fanwang marked this pull request as ready for review July 24, 2026 06:23
@shahar1 shahar1 removed the backport-to-v3-3-test Backport to v3-3-test label Jul 24, 2026
@shahar1

shahar1 commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Failed tests seem unrelated

1fanwang added 3 commits July 24, 2026 11:22
Signed-off-by: 1fanwang <1fannnw@gmail.com>
Drop exemption entries that sibling burn-down PRs already resolved on main. Net change to this file is only the ProduceToTopicOperator removal.

Signed-off-by: 1fanwang <1fannnw@gmail.com>
Signed-off-by: 1fanwang <1fannnw@gmail.com>

# Conflicts:
#	scripts/ci/prek/validate_operators_init_exemptions.txt
@shahar1
shahar1 merged commit e9a3662 into apache:main Jul 25, 2026
98 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants