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

Better error message when sqlite URL uses relative path #36774

Merged
merged 1 commit into from
Jan 14, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions airflow/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,14 @@ def configure_vars():
global PLUGINS_FOLDER
global DONOT_MODIFY_HANDLERS
SQL_ALCHEMY_CONN = conf.get("database", "SQL_ALCHEMY_CONN")
if SQL_ALCHEMY_CONN.startswith("sqlite") and not SQL_ALCHEMY_CONN.startswith("sqlite:////"):
from airflow.exceptions import AirflowConfigException

raise AirflowConfigException(
f"Cannot use relative path: `{SQL_ALCHEMY_CONN}` to connect to sqlite. "
"Please use absolute path such as `sqlite:////tmp/airflow.db`."
)

DAGS_FOLDER = os.path.expanduser(conf.get("core", "DAGS_FOLDER"))

PLUGINS_FOLDER = conf.get("core", "plugins_folder", fallback=os.path.join(AIRFLOW_HOME, "plugins"))
Expand Down
14 changes: 12 additions & 2 deletions tests/core/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
import sys
import tempfile
from unittest import mock
from unittest.mock import MagicMock, call
from unittest.mock import MagicMock, call, patch

import pytest

from airflow.exceptions import AirflowClusterPolicyViolation
from airflow.exceptions import AirflowClusterPolicyViolation, AirflowConfigException
from tests.test_utils.config import conf_vars

SETTINGS_FILE_POLICY = """
Expand Down Expand Up @@ -214,3 +214,13 @@ def test_uses_updated_session_timeout_config_by_default(self):
session_lifetime_config = settings.get_session_lifetime_config()
default_timeout_minutes = 30 * 24 * 60
assert session_lifetime_config == default_timeout_minutes


def test_sqlite_relative_path():
from airflow import settings

with patch("airflow.settings.conf.get") as conf_get_mock:
conf_get_mock.return_value = "sqlite:///./relative_path.db"
with pytest.raises(AirflowConfigException) as exc:
settings.configure_vars()
assert "Cannot use relative path:" in str(exc.value)