Skip to content
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: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ kolibri/locale/.crowdin-download-marker
.junie/
.aiassistant/
.aiignore
.codex*
.qwen/
.vibe/
.aider.config.yml

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost feels like we should just have an explicit allow list of .* files and folders, rather than excluding things (don't need to do that here).


# Complexity
output/*.html
Expand Down
23 changes: 22 additions & 1 deletion kolibri/core/content/test/test_sqlalchemy_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ class SQLAlchemyBridgeSQLAlchemyFunctionsTestCase(TestCase):
def test_sqlite_string(self):
self.assertEqual("sqlite:///test", sqlite_connection_string("test"))

def test_sqlite_uri_string(self):
self.assertEqual(
"sqlite:///file:memorydb_default?mode=memory&cache=shared&uri=true",
sqlite_connection_string("file:memorydb_default?mode=memory&cache=shared"),
)

def test_get_engine(self):
self.assertEqual(type(get_engine("sqlite:///")), Engine)

Expand Down Expand Up @@ -204,12 +210,27 @@ class SQLAlchemyBridgeDefaultDBStringTestCase(TestCase):
@pytest.mark.filterwarnings("ignore:Overriding setting DATABASES")
@override_settings(
DATABASES={
"default": {"ENGINE": "django.db.backends.sqlite3", "NAME": "test.sqlite3"}
"default": {"ENGINE": "django.db.backends.sqlite3", "NAME": "test.sqlite3"},
}
)
def test_sqlite(self):
self.assertEqual(get_default_db_string(), "sqlite:///test.sqlite3")

@pytest.mark.filterwarnings("ignore:Overriding setting DATABASES")
@override_settings(
DATABASES={
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": "file:memorydb_default?mode=memory&cache=shared",
},
}
)
def test_sqlite_uri(self):
self.assertEqual(
get_default_db_string(),
"sqlite:///file:memorydb_default?mode=memory&cache=shared&uri=true",
)

@pytest.mark.filterwarnings("ignore:Overriding setting DATABASES")
@override_settings(
DATABASES={
Expand Down
7 changes: 7 additions & 0 deletions kolibri/core/content/utils/sqlalchemybridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ def dispose(self):


def sqlite_connection_string(db_path):
# shortcut db_paths like `file:memorydb_default?mode=memory&cache=shared`
# to ensure they have `uri=true` so sqlite treats it as in-memory
if db_path.startswith("file:"):
separator = "&" if "?" in db_path else "?"
return "sqlite:///{db_path}{separator}uri=true".format(
db_path=db_path, separator=separator
)
# Call normpath to ensure that Windows paths are properly formatted
return "sqlite://{db_path}".format(
db_path="" if db_path == ":memory:" else "/" + os.path.normpath(db_path)
Expand Down
Loading