Skip to content

Use safe_repr for req.eta in logging extra context - #9533

Draft
xzkostyan wants to merge 2 commits into
celery:mainfrom
xzkostyan:fix-eta-logging
Draft

xzkostyan wants to merge 2 commits into
celery:mainfrom
xzkostyan:fix-eta-logging

Conversation

@xzkostyan

Copy link
Copy Markdown

Description

Users can define more suitable logging.Formatter for logging in applications. "data" in extra should be safe for logging in different formats like keys argsrepr and kwargsrepr.

We use json formatter for logging and json.dumps fails with TypeError: Object of type datetime is not JSON serializable.

Of course we can deal with it with

def custom_json(obj):
    if isinstance(obj, datetime):
        return obj.isoformat() 
    raise TypeError(f'Cannot serialize object of {type(obj)}')

json.dumps(..., default=custom_json)

But it's not consistent with argsrepr and kwargsrepr.

@xzkostyan

Copy link
Copy Markdown
Author

Is anything I can do with failed checks?

@auvipy auvipy 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.

you would need to add tests and fix the failing ones, due to this proposed change, also we have to figure out if this is the right choice we are going to merge

@Nusnus
Nusnus marked this pull request as draft February 9, 2025 16:15
@xzkostyan

Copy link
Copy Markdown
Author

@auvipy did you to figured this out?

@auvipy

auvipy commented Feb 20, 2025

Copy link
Copy Markdown
Member

You have to make the CI green first for your PR

@xzkostyan

Copy link
Copy Markdown
Author

also we have to figure out if this is the right choice we are going to merge

Why should I write test if this PR won't be merged?

@auvipy

auvipy commented Apr 3, 2025

Copy link
Copy Markdown
Member

I didn’t mean that, pr with tests have a higher chance to get merged as they are easier to review

@auvipy auvipy added this to the 5.7.0 milestone May 19, 2025
@Nusnus
Nusnus force-pushed the fix-eta-logging branch from 167b8a1 to d5f5f9e Compare May 31, 2025 20:49
@auvipy auvipy modified the milestones: 5.7.0, 5.8.0 Aug 26, 2026
@auvipy
auvipy requested a lite review from Copilot August 26, 2026 17:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to make the extra={'data': ...} logging payload for LOG_RECEIVED safe for JSON-style formatters by avoiding non-JSON-serializable objects (notably datetime in req.eta).

Changes:

  • Import safe_repr to stringify req.eta before placing it in the logging context.
  • Update the LOG_RECEIVED context to log eta as a safe string representation.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread celery/worker/strategy.py
Comment on lines 156 to +160
'id': req.id,
'name': req.name,
'args': req.argsrepr,
'kwargs': req.kwargsrepr,
'eta': req.eta,
'eta': safe_repr(req.eta),

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants