Skip to content

Commit

Permalink
fix(ingest/file-backed-collections): Properly set _use_sqlite_on_conf…
Browse files Browse the repository at this point in the history
…lict (#12297)
  • Loading branch information
asikowitz authored Jan 8, 2025
1 parent 58b6a5b commit 92f013e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def __post_init__(self) -> None:
# This was added in 3.24.0 from 2018-06-04.
# See https://www.sqlite.org/lang_conflict.html
if OVERRIDE_SQLITE_VERSION_REQUIREMENT:
self.use_sqlite_on_conflict = False
self._use_sqlite_on_conflict = False
else:
raise RuntimeError("SQLite version 3.24.0 or later is required")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import sqlite3
from dataclasses import dataclass
from typing import Counter, Dict
from unittest.mock import patch

import pytest

Expand All @@ -15,6 +16,36 @@
)


def test_set_use_sqlite_on_conflict():
with patch("sqlite3.sqlite_version_info", (3, 24, 0)):
cache = FileBackedDict[int](
tablename="cache",
cache_max_size=10,
cache_eviction_batch_size=10,
)
assert cache._use_sqlite_on_conflict is True

with pytest.raises(RuntimeError):
with patch("sqlite3.sqlite_version_info", (3, 23, 1)):
cache = FileBackedDict[int](
tablename="cache",
cache_max_size=10,
cache_eviction_batch_size=10,
)
assert cache._use_sqlite_on_conflict is False

with patch("sqlite3.sqlite_version_info", (3, 23, 1)), patch(
"datahub.utilities.file_backed_collections.OVERRIDE_SQLITE_VERSION_REQUIREMENT",
True,
):
cache = FileBackedDict[int](
tablename="cache",
cache_max_size=10,
cache_eviction_batch_size=10,
)
assert cache._use_sqlite_on_conflict is False


@pytest.mark.parametrize("use_sqlite_on_conflict", [True, False])
def test_file_dict(use_sqlite_on_conflict: bool) -> None:
cache = FileBackedDict[int](
Expand Down

0 comments on commit 92f013e

Please sign in to comment.