Make airflowctl command generation safe to read more than once - #73097
Open
Eason09053360 wants to merge 1 commit into
Open
Make airflowctl command generation safe to read more than once#73097Eason09053360 wants to merge 1 commit into
Eason09053360 wants to merge 1 commit into
Conversation
The generated command tree is exposed through a module-level CommandFactory singleton that anyone can import, so a second read of the property is a reachable state rather than a hypothetical one. Today only the single import-time access exists, which is why nothing is visibly broken; the most likely way in is a routine test refactor that shares one factory instance across cases, which would then fail in a way that points nowhere near the cause.
Eason09053360
requested review from
bugraoz93,
dheerajturaga,
henry3260 and
potiuk
as code owners
September 13, 2026 16:38
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
CommandFactory.group_commandsinairflow-ctl/src/airflowctl/ctl/cli_config.pyis a plain@property, so every access re-runs the four builder methods. Those builders append toself.operations,self.commands_mapandself.group_commands_listinstead of replacing them,and the
GroupCommands hold thecommands_maplists by reference. Reading the property a secondtime therefore doubles the command tree:
Two groups named
connectionsis not somethingargparseaccepts, so the second read leavesairflowctlunable to build its parser at all.This is preventive — there is no user-visible bug today, because the only access is the single
import-time one at
cli_config.py:1305. What makes it worth fixing now is thatcommand_factoryis a module-level singleton any caller can import, and the existing tests construct
CommandFactory()in a dozen places. The likely way in is a routine refactor that shares onefactory instance across test cases; the resulting failure would point nowhere near this property.
What
cli_config.py:group_commandsbecomes acached_property, so the non-idempotent buildersrun once per instance. The docstring records why the caching is load-bearing rather than an
optimisation, since reverting it to
@propertywould keep every current test green.test_cli_config.py: addstest_group_commands_is_stable_across_repeated_access. Both accessesreturn the same list object, so the test snapshots
(name, len(subcommands))before the secondaccess — comparing the lists directly would compare a list against itself and pass either way.
Nothing mutates the cached list:
merge_commandsandadd_auth_token_to_all_commandsboth copybefore extending and rebuild the namedtuples via
_replace.Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code (Opus 5) following the guidelines