GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — sqlite3: exception from a collation callback is replaced by SystemError · Issue #161837 · python/cpython

sqlite3: exception from a collation callback is replaced by SystemError #161837

New issue
Copy link
New issue
Copy link
Open
Open
sqlite3: exception from a collation callback is replaced by SystemError#161837
Copy link
Labels
extension-modulesC modules in the Modules dirC modules in the Modules dirtopic-sqlite3type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@grgalex
grgalex
opened on Nov 12, 2026
Issue body actions

Bug report

Summary

When a collation callback raises, sqlite3 returns 0 to SQLite and leaves the exception pending. SQLite keeps evaluating the row, and a later failure in the same step (here abs() of the smallest 64-bit integer, an integer overflow) makes sqlite3 build its own OperationalError with the collation's exception still set. The interpreter reports this as a SystemError, and the original exception is lost.

Expected: the collation's exception should propagate, or at least chain as the cause.

Reproducer

import sqlite3

def coll(a, b):
    if a == "boom":
        raise KeyError("collation raised")
    return (a > b) - (a < b)

con = sqlite3.connect(":memory:")
con.create_collation("c", coll)
con.execute("create table t(x, y)")
con.executemany("insert into t values (?, ?)",
                [(1, "a"), (-9223372036854775808, "boom")])
cur = con.execute("select case when y = 'q' collate c then abs(x) else 0 end from t")
cur.fetchone()
KeyError: 'collation raised'

The above exception was the direct cause of the following exception:

SystemError: <class 'sqlite3.OperationalError'> returned a result with an exception set

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

  • gh-161837: Fix crashes in sqlite3 when a collation callback raises #161845

Activity

  1. grgalex
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Nov 12, 2026
  2. ZeroIntensity
    added
    extension-modulesC modules in the Modules dirC modules in the Modules dir
    topic-sqlite3
    on Nov 12, 2026
  3. github-project-automation
    added this to sqlite3 issueson Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    extension-modulesC modules in the Modules dirC modules in the Modules dirtopic-sqlite3type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    • sqlite3 issues
      Status
      No status
      Show more project fields

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.