Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: NO_SUCH_TABLE regex #495

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/shillelagh/backends/apsw/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
int(number) for number in apsw.sqlitelibversion().split(".")
)

NO_SUCH_TABLE = re.compile("(?:SQLError: )?no such table: (?P<uri>.*)")
NO_SUCH_TABLE = re.compile("no such table: (?P<uri>.*)")
DEFAULT_SCHEMA = "main"

CURSOR_METHOD = TypeVar("CURSOR_METHOD", bound=Callable[..., Any])
Expand Down Expand Up @@ -250,7 +250,7 @@ def execute(
break
except apsw.SQLError as ex:
message = ex.args[0]
if match := NO_SUCH_TABLE.match(message):
if match := NO_SUCH_TABLE.search(message):
# create the virtual table
uri = match.groupdict()["uri"]
self._create_table(uri)
Expand Down
23 changes: 22 additions & 1 deletion tests/backends/apsw/db_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@
from pytest_mock import MockerFixture

from shillelagh.adapters.registry import AdapterLoader, UnsafeAdaptersError
from shillelagh.backends.apsw.db import Connection, connect, convert_binding
from shillelagh.backends.apsw.db import (
NO_SUCH_TABLE,
Connection,
connect,
convert_binding,
)
from shillelagh.exceptions import NotSupportedError, ProgrammingError
from shillelagh.fields import Float, String, StringInteger

Expand Down Expand Up @@ -541,3 +546,19 @@ def test_best_index(mocker: MockerFixture) -> None:
"some_adapter",
VTModule(adapter),
)


@pytest.mark.parametrize(
"error,uri",
[
("apsw.SQLError: no such table: dummy://", "dummy://"),
("SQLError: no such table: dummy://", "dummy://"),
("no such table: dummy://", "dummy://"),
],
)
def test_no_such_table_search(error: str, uri: str) -> None:
"""
Test ``NO_SUCH_TABLE`` search.
"""
match = NO_SUCH_TABLE.search(error)
assert match and match.groupdict() == {"uri": uri}
Loading