Prevent scheduler crash when process/thread missing from log format#69402
Open
anxkhn wants to merge 1 commit into
Open
Prevent scheduler crash when process/thread missing from log format#69402anxkhn wants to merge 1 commit into
anxkhn wants to merge 1 commit into
Conversation
When a record reaches the percent formatter without callsite information, for example a stdlib warning routed through the logging bridge, the process and thread fields are absent. The formatter fell back to the "(unknown)" string for them, so a format string using the numeric "%(process)d" or "%(thread)d" specifiers raised "TypeError: %d format: a real number is required" and could take down the scheduler at startup. Give those two numeric callsite parameters a numeric fallback of 0, the same way lineno is already handled, so the format never receives a string where a number is expected.
potiuk
approved these changes
Jul 5, 2026
Member
|
Nice! |
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.
When a log record reaches the percent formatter without callsite information, for
example a standard-library warning routed through Airflow's logging bridge, the
processandthreadfields are absent. The formatter fell back to the"(unknown)"string for every missing callsite field, so a log format usingthe numeric
%(process)dor%(thread)dspecifiers (the default consoleformat renders a process-id column) raised
TypeError: %d format: a real number is required, not strand could take downthe scheduler at startup.
This gives those two numeric callsite parameters a numeric fallback of
0, thesame way
linenois already handled a few lines above, so the format stringnever receives a string where a number is expected. The
"(unknown)"stringfallback is left intact for the text callsite parameters
(
pathname/module/threadName/processName), which are rendered with%s.A parametrized regression test formats
%(process)d:%(thread)dfor a recordwith no callsite info (the exact issue reproduction) and for one where those keys
are explicitly
None, asserting it renders0:0instead of raising; it failswith the
TypeErrorbefore the change and passes after.closes: #66195
Was generative AI tooling used to co-author this PR?
Final diff (2 files, +24/-0)
shared/logging/src/airflow_shared/logging/percent_formatter.py(+6): in_LazyLogRecordDict.__getitem__, addif key == "process" or key == "thread": return self.event.get(key) or 0immediately after the existing
linenonumeric-fallback case, with a shortcomment explaining why (numeric
%dparams must not fall back to the"(unknown)"string used for text params).shared/logging/tests/logging/test_percent_formatter.py(+18): addtest_numeric_callsite_without_process_or_thread, parametrizedmissing(no callsite keys, the issue repro) and
none(keys present butNone), inthe existing
TestPercentFormatRenderclass next totest_no_callsite; addsthe
import pytestit needs.