You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Global exception translator turns other pybind11 modules' C++ exceptions into RuntimeError (breaks DuckDB error types) #314
Note: AI was used to write this issue, but I verified its output. This is an issue I encountered in a real world setting.
Description
pulsar-client registers a global pybind11 exception translator that ends in a catch-all for std::exception. That translator applies to every pybind11 module in the process, and pybind11 tries global translators newest-first. So when pulsar is imported after another pybind11 extension, C++ exceptions from that extension no longer get their proper Python types. They become a plain RuntimeError.
We hit this with DuckDB. Once pulsar is imported, duckdb.CatalogException and the other DuckDB exception types come through as RuntimeError. That breaks any code that catches DuckDB's specific exceptions. In our case, dlt's DuckDB/filesystem SQL client failed to open connections, because it relies on catching duckdb.CatalogException.
Reproduction
importduckdbimportpulsar# imported after duckdb; swap these two lines and it worksconn=duckdb.connect(":memory:")
try:
conn.execute("SET search_path = 'does_not_exist'")
exceptduckdb.CatalogExceptionase:
print(f"OK: {type(e).__name__}")
exceptRuntimeErrorase:
print(f"BUG: {type(e).__name__}: {e}")
Output:
BUG: RuntimeError: {"exception_type":"Catalog","exception_message":"SET search_path: No catalog + schema named \"does_not_exist\" found."}
With import pulsar before import duckdb, it prints OK: CatalogException.
register_exception_translator registers a global translator. Because of the final catch (const std::exception&), it handles every C++ exception from any pybind11 module that was loaded earlier. Those modules' own translators never run. The pybind11 docs warn about this: translators that don't handle an exception should rethrow it, and global translators make behavior depend on import order.
Suggested fix
Either of these fixes it:
Register the translator as module-local (pybind11 ≥ 2.8). It then only applies to exceptions thrown from _pulsar, and is still tried before any global translator:
Or keep the global registration but drop the std::exception catch-all, so exceptions pulsar doesn't own reach the translators registered before it. pybind11's default handling already maps std::exception to RuntimeError for _pulsar itself, so Pulsar's behavior wouldn't change.
Option 1 seems the most robust.
Environment
pulsar-client 3.13.0 (the code is unchanged on main)
duckdb 1.5.3
Python 3.13.14, Linux x86_64 (glibc 2.41)
Workaround
Import pulsar before any other pybind11-based extension, such as duckdb, so its translator is registered first and the other modules' translators take precedence.
Activity
fix: register exception translator as module-local