Repository navigation
Report the real reason the C extension failed to load - #153
Merged
Merged
Conversation
kesmit13
requested review from
bharathts07,
mgiannakopoulos,
pmishchenko-ua and
volodymyr-memsql
as code owners
October 29, 2026 13:47
With pure_python=False and a C extension that failed to import, the connection retries the import only to print why, then raises NotSupportedError. The retry misspelled the module name, so stderr always showed "No module named '_singlestortedb_accel'" and hid the real loader error (a missing symbol, wrong architecture, too-old glibc, ...). Correcting the spelling in the import statement isn't enough: an import statement in __init__ binds _singlestoredb_accel as a local for the whole function, so the module-level checks before and after it raise UnboundLocalError and every connection fails. The typo was avoiding that. Retry with importlib.import_module instead, which binds nothing. The new tests need no server. One makes the extension import fail and checks that stderr carries that error; it fails with the old typo. The other builds a pure_python=False connection while the extension is available; it fails with the plain import-statement fix. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kesmit13
force-pushed
the
fix-accel-import-diagnostic
branch
from
October 29, 2026 14:45
bccb277 to
ce6c69c
Compare
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a connection is opened with
pure_python=Falseand the C extension failed to import,Connection.__init__retries the import only so it can print why, then raisesNotSupportedError. The retry misspelled the module (_singlestortedb_accel), so stderr always showed:That hid the real loader error, such as a missing symbol, the wrong architecture or a too-old glibc. It only matters with an explicit
pure_python=False; the defaultNonefalls back to pure Python without printing anything. But that is exactly whatpublish.yml's wheel tests use (?pure_python=0inSINGLESTOREDB_URL), so a broken wheel in CI would have reported the wrong cause.Why this isn't a one-letter fix
Correcting the spelling of the
importstatement breaks every connection. Animportstatement anywhere in__init__makes_singlestoredb_accellocal to the whole function, so the_singlestoredb_accel is Nonecheck before it and theelif _singlestoredb_accel is not Noneafter it raiseUnboundLocalError. The typo was avoiding that, most likely by accident. This retries withimportlib.import_module('_singlestoredb_accel')instead, which doesn't bind any name.Tests
singlestoredb/tests/test_accel_import.py; neither test needs a server:test_reports_the_real_import_errormakes the extension import fail with a specificImportErrorby adding a finder tosys.meta_path, which animportstatement andimportlibboth go through. It then checks that the error appears on stderr. It fails with the old typo.test_loads_when_availablebuilds apure_python=Falseconnection (defer_connect=True) while the extension is available and checks that the C result class is used. It fails with the one-letter fix, raisingUnboundLocalError. It's skipped when the extension isn't built.I ran it locally against a
singlestoredb-devcontainer.test_basics.py,test_accel_leaks.pyand the new tests pass, andtest_basics.pyplus the new tests also pass withSINGLESTOREDB_PURE_PYTHON=1. Pre-commit is clean.🤖 Generated with Claude Code
Note
Low Risk
Narrow change to error reporting and import retry when pure_python=False; behavior for default connections is unchanged.
Overview
When
pure_python=Falseand the C extension did not load at import time,Connection.__init__retries the load only to print the failure to stderr before raisingNotSupportedError. That retry used a misspelled module name (_singlestortedb_accel), so CI and users sawModuleNotFoundErrorinstead of the real loader error (e.g. missing GLIBC).The fix loads
_singlestoredb_accelviaimportlib.import_module, which retries the correct module without introducing a local binding that would break the existing_singlestoredb_accel is Nonechecks in__init__(a plainimportthere would causeUnboundLocalErroron every connection).Adds
test_accel_import.py: one test asserts stderr contains a simulated import failure; another (when the extension is built) assertspure_python=Falsestill selects the C result class.Reviewed by Cursor Bugbot for commit ce6c69c. Bugbot is set up for automated code reviews on this repo. Configure here.