Skip to content

Commit 3d81d51

Browse files
authored
Merge pull request #12 from AnswerDotAI/remove-operational-error
Remove OperationError
2 parents fda2a36 + 8b79c1b commit 3d81d51

File tree

5 files changed

+10
-16
lines changed

5 files changed

+10
-16
lines changed

apswutils/db.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# This file is from sqlite-utils and copyright and license is the same as that project
22
__all__ = ['Database', 'Queryable', 'Table', 'View']
33

4-
from .utils import chunks, hash_record, OperationalError, suggest_column_types, types_for_column_types, column_affinity, find_spatialite
4+
from .utils import chunks, hash_record, suggest_column_types, types_for_column_types, column_affinity, find_spatialite
55
from collections import namedtuple
66
from collections.abc import Mapping
77
from typing import cast, Any, Callable, Dict, Generator, Iterable, Union, Optional, List, Tuple, Iterator
88
from functools import cache
99
import contextlib, datetime, decimal, inspect, itertools, json, os, pathlib, re, secrets, textwrap, binascii, uuid, logging
10-
import apsw.ext, apsw.bestpractice
10+
import apsw, apsw.ext, apsw.bestpractice
1111

1212
logger = logging.getLogger('apsw')
1313
logger.setLevel(logging.ERROR)
@@ -684,7 +684,7 @@ def cached_counts(self, tables: Optional[Iterable[str]] = None) -> Dict[str, int
684684
sql += " where [table] in ({})".format(", ".join("?" for table in tables))
685685
try:
686686
return {r[0]: r[1] for r in self.execute(sql, tables).fetchall()}
687-
except OperationalError:
687+
except apsw.Error:
688688
return {}
689689

690690
def reset_counts(self):
@@ -2118,7 +2118,7 @@ def create_index(
21182118
try:
21192119
self.db.execute(sql)
21202120
break
2121-
except OperationalError as e:
2121+
except apsw.SQLError as e:
21222122
# find_unique_name=True - try again if 'index ... already exists'
21232123
arg = e.args[0]
21242124
if (
@@ -2769,7 +2769,7 @@ def update(
27692769

27702770
for row in cursor:
27712771
self.result.append(dict(zip(columns, row)))
2772-
except OperationalError as e:
2772+
except apsw.SQLError as e:
27732773
if alter and (" column" in e.args[0]):
27742774
# Attempt to add any missing columns, then try again
27752775
self.add_missing_columns([updates])
@@ -2934,7 +2934,7 @@ def insert_chunk(
29342934
except apsw.ExecutionCompleteError: continue
29352935
for row in cursor:
29362936
records.append(dict(zip(columns, row)))
2937-
except OperationalError as e:
2937+
except apsw.SQLError as e:
29382938
if alter and (" column" in e.args[0]):
29392939
# Attempt to add any missing columns, then try again
29402940
self.add_missing_columns(chunk)

apswutils/utils.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@
1313
from typing import Dict, cast, BinaryIO, Iterable, Optional, Tuple, Type
1414
import apsw
1515

16-
# TODO: Replace use of OperationalError with more explicit apsw errors
17-
# In order to keep this PR minimal, we use OperationalError as a shim for apsw.Error
18-
OperationalError = apsw.Error
19-
2016
SPATIALITE_PATHS = (
2117
"/usr/lib/x86_64-linux-gnu/mod_spatialite.so",
2218
"/usr/lib/aarch64-linux-gnu/mod_spatialite.so",

tests/test_create.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
DescIndex,
55
AlterError,
66
NoObviousTable,
7-
OperationalError,
87
ForeignKey,
98
Table,
109
View,
@@ -717,7 +716,7 @@ def test_columns_not_in_first_record_should_not_cause_batch_to_be_too_large(fres
717716
fresh_db["too_many_columns"].insert_all(
718717
records, alter=True, batch_size=batch_size
719718
)
720-
except OperationalError:
719+
except apsw.SQLError:
721720
raise
722721

723722

@@ -817,7 +816,7 @@ def test_create_index_find_unique_name(fresh_db):
817816
table.insert({"id": 1})
818817
table.create_index(["id"])
819818
# Without find_unique_name should error
820-
with pytest.raises(OperationalError, match="index idx_t_id already exists"):
819+
with pytest.raises(apsw.SQLError, match="index idx_t_id already exists"):
821820
table.create_index(["id"])
822821
# With find_unique_name=True it should work
823822
table.create_index(["id"], find_unique_name=True)

tests/test_create_view.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import pytest
2-
from apswutils.utils import OperationalError
2+
import apsw
33

44

55
def test_create_view(fresh_db):
@@ -10,7 +10,7 @@ def test_create_view(fresh_db):
1010

1111
def test_create_view_error(fresh_db):
1212
fresh_db.create_view("bar", "select 1 + 1")
13-
with pytest.raises(OperationalError):
13+
with pytest.raises(apsw.SQLError):
1414
fresh_db.create_view("bar", "select 1 + 2")
1515

1616

tests/test_transform.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from apswutils.db import ForeignKey
2-
from apswutils.utils import OperationalError
32
import pytest
43
import apsw
54
from collections.abc import Mapping

0 commit comments

Comments
 (0)