Skip to content

Add log_note execution option - #13435

Open
Yijian6 wants to merge 1 commit into
sqlalchemy:mainfrom
Yijian6:log-note-execution-option
Open

Add log_note execution option#13435
Yijian6 wants to merge 1 commit into
sqlalchemy:mainfrom
Yijian6:log-note-execution-option

Conversation

@Yijian6

@Yijian6 Yijian6 commented Jul 15, 2026

Copy link
Copy Markdown

What

Adds a typed Core log_note execution option for Engine, Connection, SQL statements, and per-execution options. The note appears in brackets immediately after the cache statistics badge in the statement parameter log record.

Why

Issue #7732 requests a way to tag individual SQL executions in logs without changing the SQL string or compiled cache key. This PR implements the Core portion; automatic notes for ORM eager, lazy, and deferred loaders remain a separate follow-up.

How

DefaultExecutionContext formats the effective note once, and both ordinary execution and insertmanyvalues logging paths append it after cache statistics. The option is included in synchronous, asynchronous, statement, legacy Query, and known execution-option typing surfaces. Existing log output remains unchanged when the option is absent or empty, including hidden-parameter output.

Core logging documentation and a SQLAlchemy 2.1 changelog entry are included.

Testing

  • python -m pytest -n 0 test/engine/test_logging.py test/typing/test_overloads.py -q — 86 passed
  • python -m mypy on the six changed source modules
  • Black, zimports, flake8, and tools/format_docs_code.py --check
  • Sphinx HTML build with the changed pages rebuilt under -W

Coverage includes per-execution, statement, connection, and engine scopes; empty notes; hidden parameters; and multi-batch insertmanyvalues logging.

Breaking changes

None.

Checklist

This pull request is:

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.

1 participant