In csvpath/util/sqliter.py, Sqliter.init is:
def __init__(self, *, config: Config, client_class: Type[Any] = None) -> None:
...
self._client_class = client_class if client_class is not None else type(self)
client_class is used in _setup_db() to locate a schema.sql file next to whichever class module is passed:
path = Code.get_source_path(self._client_class)
path = os.path.dirname(path)
path = os.path.join(path, "schema.sql")
If client_class is omitted, it defaults to type(self), i.e. Sqliter itself. But csvpath/util/ (Sqliter's own directory) has no schema.sql -- the real schema lives at csvpath/managers/integrations/sqlite/schema.sql, next to the two current callers (SqliteResultListener, SqliteResultsListener), both of which always pass client_class explicitly.
So omitting client_class only happens to work if the target db file already exists (db_file only calls _setup_db() on first creation). Passing no client_class while creating a brand new db raises FileNotFoundError trying to open a schema.sql that does not exist in csvpath/util/.
Discussed with David: likely resolution is that this should be treated as a real bug -- the caller should always be required to pass client_class (or client_class should not default to Sqliter itself, since Sqliter has no business owning its own schema.sql). Revisiting later; for now this is tests-only, documented with a regression test in tests/util/test_util_sqliter.py (test_default_client_class_cannot_find_its_own_schema) on branch test/util-line-monitor-io-spooler.
In csvpath/util/sqliter.py, Sqliter.init is:
client_class is used in _setup_db() to locate a schema.sql file next to whichever class module is passed:
If client_class is omitted, it defaults to type(self), i.e. Sqliter itself. But csvpath/util/ (Sqliter's own directory) has no schema.sql -- the real schema lives at csvpath/managers/integrations/sqlite/schema.sql, next to the two current callers (SqliteResultListener, SqliteResultsListener), both of which always pass client_class explicitly.
So omitting client_class only happens to work if the target db file already exists (db_file only calls _setup_db() on first creation). Passing no client_class while creating a brand new db raises FileNotFoundError trying to open a schema.sql that does not exist in csvpath/util/.
Discussed with David: likely resolution is that this should be treated as a real bug -- the caller should always be required to pass client_class (or client_class should not default to Sqliter itself, since Sqliter has no business owning its own schema.sql). Revisiting later; for now this is tests-only, documented with a regression test in tests/util/test_util_sqliter.py (test_default_client_class_cannot_find_its_own_schema) on branch test/util-line-monitor-io-spooler.