boulce opened a new pull request, #77740:
URL: https://github.com/apache/airflow/pull/77740

   `PercentFormatRender` returned `None` for the stdlib LogRecord keys `msecs` 
and `levelno`. With a `[logging] log_format` such as `"%(asctime)s.%(msecs)03d 
%(levelname)s - %(message)s"`, every log line raised `TypeError: %d format: a 
real number is required, not NoneType`. Structlog loggers raised it to the 
caller. Stdlib loggers printed `--- Logging error ---` and dropped the message.
   
   In Airflow 2 the same `log_format` worked, because it went to a 
`logging.Formatter` subclass (`TimezoneAware`). That makes this a regression 
for anyone upgrading with such a format.
   
   Neither key is in the event dict, and the LogRecord is gone by the time the 
renderer runs, so the renderer derives them:
   
   - `levelno` comes from the level name through structlog's `NAME_TO_LEVEL`, 
as `structlog.py` does. An unknown name gives `0`, like the 
`lineno`/`process`/`thread` fallbacks.
   - `msecs` comes from the event's `timestamp` when it has sub-second digits 
(a `datetime`, or a string such as `2026-11-28T01:02:03.045678Z`). This keeps 
`msecs` in line with `asctime` for lines re-logged with an older timestamp: the 
triggerer re-logs its runner subprocess's lines, and the task supervisor 
re-logs a task's lines with the subprocess's timestamp. If the timestamp has no 
sub-second digits, for example with `log_timestamp_format = %Y-%m-%d %H:%M:%S` 
(the documented example), `msecs` comes from the current time, computed from 
`time_ns()` the way stdlib does since 3.13. Rendering runs inside the log call.
   
   `%(created)f` and `%(relativeCreated)d` are left unchanged, because 
`created` currently renders the timestamp string and changing it would change 
existing output.
   
   Tests: added cases to `test_percent_formatter.py`. `shared/logging/tests` 
passes (119 tests), and ruff and mypy pass on the changed file. The full CI 
suite also passed on my fork.
   
   related: #66195 (same failure path; #69402 fixed it for 
`%(process)d`/`%(thread)d`)
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [X] Yes (please specify the tool below)
   
   Generated-by: Claude Code (Claude Opus 5.5) following [the 
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
   
   ---
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


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

  • [PR] Fix TypeError for %(msecs... boulce (via GitHub) via commits

Reply via email to