Fix structlog handling of dict arguments in logging calls#62258
Fix structlog handling of dict arguments in logging calls#62258SakshamSinghal20 wants to merge 5 commits intoapache:mainfrom
Conversation
amoghrajesh
left a comment
There was a problem hiding this comment.
Looking at this more closely, this is not a valid way of logging dictionaries.
Since we use underneath stdlib logging, it will crash which is expected. Running this:
import logging
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
logger.warning("Info message %s", {"a": 10})would crash too. The right way to log a dict would be: logger.warning("Info message %s", str({"a": 10}))
Thank You @amoghrajesh for letting me know I will change this ASAP. |
@amoghrajesh Wait, I'm a little confused. You're saying this example should fail, but it doesn't seem to when I test it out, screenshot below. Would be curious if it's a version difference, or if I'm misunderstanding.
|
|
@amoghrajesh I’ve addressed your feedback and pushed the necessary changes. Could you please review it again when you get a chance? |
|
@potiuk Would you like to look at this once and tell if everything is correctly implemented or not? |
|
@SakshamSinghal20 This PR has a few issues that need to be addressed before it can be reviewed — please see our Pull Request quality criteria. Issues found:
What to do next:
Please address the issues above and push again. If you have questions, feel free to ask on the Airflow Slack. |
|
@SakshamSinghal20 This PR has been converted to draft because it does not yet meet our Pull Request quality criteria. Issues found:
What to do next:
Converting a PR to draft is not a rejection — it is an invitation to bring the PR up to the project's standards so that maintainer review time is spent productively. There is no rush — take your time and work at your own pace. We appreciate your contribution and are happy to wait for updates. If you have questions, feel free to ask on the Airflow Slack. |
|
@potiuk sorry for the inactivity, i have updated my branch. |

Description
Fixes #62201: structlog configuration fails with dict input
When a dictionary is passed as a positional argument to a logging message
(e.g.,
logging.getLogger(__name__).warning('Info message %s', {'a': 10})),Airflow's structlog processor incorrectly treats the dict as structured context
instead of a value for string interpolation, causing a crash.
This fix modifies the structlog processor to convert dict arguments to their
string representation before processing, ensuring backward compatibility with
existing structured logging functionality.
Changes Made
airflow/utils/log/to handle dict argumentsTesting
logging.getLogger(__name__).warning('Info message %s', {'a': 10})Related Issues
Was generative AI tooling used to co-author this PR?