Repository navigation
Report invalid source schemes as OperationalError - #296
ryanduguid wants to merge 4 commits into
Conversation
| missing_source = ( | ||
| exc.name == source_name or | ||
| (exc.name is not None and exc.name.startswith('beanquery.sources.') and | ||
| source_name.startswith(f'{exc.name}.')) | ||
| ) |
There was a problem hiding this comment.
Can you explain what this code is doing? I cannot understand why it is needed in the form it is written.
There was a problem hiding this comment.
Python can name a missing parent package instead of the requested module. For foo.bar:ledger, the import requests beanquery.sources.foo.bar, but exc.name can be beanquery.sources.foo.
The predicate converts a missing source module or one of its parents below beanquery.sources to OperationalError. It re-raises unrelated dependency errors, and excludes beanquery.sources itself. source.attach() runs outside the handler so its failures also propagate.
I've named exc.name locally and added a comment explaining the dotted-parent case. The real dotted-scheme and dependency tests pass, along with all 303 Linux tests, Ruff, ten Windows connection tests and both package builds.
There was a problem hiding this comment.
This seems still very much LLM crap. I warned you. Goodbye
Summary
Report a missing or unknown source scheme as
OperationalError, following the connection error contract in PEP 249. For example,connect('unknown:ledger')reportsunknown source scheme: 'unknown'. Messages contain only the scheme.The import handler recognises a missing source module or a missing parent of a dotted source scheme. Genuine dependency errors propagate, and source attachment runs outside that handler. A short comment and a local name explain the parent-module comparison.
Fixes #247.
Evidence
ModuleNotFoundErrorsubcase errors. The final clarification passes all 303 tests and Ruff on Linux Python 3.11.16 / Beancount 3.2.3; all ten connection tests also pass on Windows Python 3.11.Merge danger
Door: two-way. Blast radius: source connections.
Callers catching
ModuleNotFoundErrorfor invalid DSNs will need to catchOperationalError.Unverified
Upstream checks and maintainer review remain outstanding. The full Windows baseline has temporary-file handle errors and a CSV newline failure. The current Aikido rescan timed out connecting and supplies no fresh scan result.