Skip to content

Fix TypeError when a task log event has a key named target or msg - #75029

Open
liwenjie200543 wants to merge 3 commits into
apache:mainfrom
liwenjie200543:fix/log-to-target-positional-only
Open

liwenjie200543 wants to merge 3 commits into
apache:mainfrom
liwenjie200543:fix/log-to-target-positional-only

Conversation

@liwenjie200543

Copy link
Copy Markdown
Contributor

What

process_log_messages_from_subprocess spreads every remaining key of a subprocess log event into _log_to_target(target, level, msg, **event). A log event carrying a key named target or msg collides with the helper's own parameter names and raises TypeError. Nothing in the supervisor loop catches it, so the heartbeat stops, the child process (in its own process group) is never killed, and a successful task is recorded as failed — the repro and trace are in the issue.

This makes the first three parameters positional-only (/), so event keys can no longer collide with them and every key is forwarded as a kwarg. Non-reserved keys (environment= etc.) behave exactly as before.

Checks

  • Reproduced locally against the exact upstream functions with structlog 26.1.0 + msgspec: target=/msg= events raised TypeError before the change and are forwarded unchanged after it; a real structlog logger renders target=prod / msg=prod as expected.
  • _log_to_target has two call sites (process_log_messages_from_subprocess and forward_to_log), both pass the first three arguments positionally, so the / marker changes no existing call.
  • Added a regression test asserting both reserved-key events are logged without error.

Fixes: #75017

The supervisor spreads every remaining key of a subprocess log event into
`_log_to_target(target, level, msg, **event)`; an event carrying a key named
`target` or `msg` collided with the helper parameters and raised a TypeError
that escaped the supervisor loop, orphaning the task process and recording a
successful task as failed. Make the first three parameters positional-only
so event keys are always forwarded as kwargs, and add a regression test.

Fixes: apache#75017

@FrankYang0529 FrankYang0529 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Leave one minor comment. Thanks.

@liwenjie200543

Copy link
Copy Markdown
Contributor Author

@FrankYang0529 thanks again — the test is now parametrized (target / msg) and the review thread is resolved.

I've also updated the branch onto current main (it had drifted 595 commits), so CI now runs against the latest base. Head is bf000b65; the change itself is untouched: task-sdk +23/−1 across the same two files.

GitHub dropped the earlier approval because of that follow-up push, so reviewDecision went back to REVIEW_REQUIRED. That is the only thing blocking the merge now — would you mind re-approving the latest commit once CI is green?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

2 participants