Skip to content

Expose Cursor.warning_count#780

Draft
Copilot wants to merge 2 commits into
mainfrom
copilot/add-cursor-warning-count
Draft

Expose Cursor.warning_count#780
Copilot wants to merge 2 commits into
mainfrom
copilot/add-cursor-warning-count

Conversation

Copy link
Copy Markdown

Copilot AI commented Jun 8, 2026

This ports PyMySQL’s Cursor.warning_count behavior to mysqlclient so callers can inspect whether the last operation produced warnings without issuing an extra round-trip. It also keeps unbuffered cursors in sync once the result stream is fully consumed.

  • What changed

    • Added Cursor.warning_count to the base cursor state.
    • Populate it from Connection.warning_count() after each query result is obtained.
    • Reset it at query start to avoid leaking stale values across statements.
  • Unbuffered cursor behavior

    • Update SSCursor.warning_count when the result set is exhausted via:
      • fetchone()
      • fetchmany()
      • fetchall()
    • This matches the point at which server-side cursors have fully observed warning state.
  • Regression coverage

    • Added focused tests for buffered and unbuffered cursors covering:
      • statement warnings (DROP TABLE IF EXISTS on a missing table)
      • clearing back to 0 on a warning-free statement
      • warning propagation after fully consuming an unbuffered result
cur.execute("DROP TABLE IF EXISTS `no_exists_table`")
assert cur.warning_count == 1

cur.execute("SELECT 1")
assert cur.warning_count == 0

Copilot AI linked an issue Jun 8, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Add cursor.warning_count to mysqlclient Expose Cursor.warning_count Jun 8, 2026
Copilot AI requested a review from methane June 8, 2026 09:33
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.

Add Cursor.warning_count

2 participants