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

Support dbt version 1.8 #58

Merged
merged 12 commits into from
Jun 4, 2024
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,6 @@ src/pytest_dbt_core/_version.py
# dbt
.user.yml
dbt_packages/

# Editor
.idea/
7 changes: 7 additions & 0 deletions docs/source/_static/dbt_project/macros/spark_adapter.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% macro spark__list_relations_without_caching(relation) %}
{% call statement('list_relations_without_caching', fetch_result=True) -%}
show table extended in {{ relation }} like '*'
{% endcall %}

{% do return(load_result('list_relations_without_caching').table) %}
{% endmacro %}
6 changes: 4 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ spark_options =
[tox:tox]
envlist =
py3.7-dbt-spark{11,12,13,14,15} # dbt-spark v1.6 or later does not support Python 3.7
py{3.8,3.9,3.10}-dbt-spark{11,12,13,14,15,16,17}
py3.11-dbt-spark{14,15,16,17} # Previous dbt-spark versions fail when using Python 3.11
py{3.8,3.9,3.10}-dbt-spark{11,12,13,14,15,16,17,18}
py3.11-dbt-spark{14,15,16,17,18} # Previous dbt-spark versions fail when using Python 3.11
isolated_build = true
skip_missing_interpreters = true

Expand All @@ -95,6 +95,7 @@ deps =
dbt-spark15: dbt-spark[ODBC]~=1.5.0
dbt-spark16: dbt-spark[ODBC]~=1.6.0
dbt-spark17: dbt-spark[ODBC]~=1.7.0
dbt-spark18: dbt-spark[ODBC]~=1.8.0
pip >= 19.3.1
extras = test
commands = pytest {posargs:tests}
Expand All @@ -115,6 +116,7 @@ deps =
dbt-spark15: dbt-spark[ODBC]~=1.5.0
dbt-spark16: dbt-spark[ODBC]~=1.6.0
dbt-spark17: dbt-spark[ODBC]~=1.7.0
dbt-spark18: dbt-spark[ODBC]~=1.8.0
pip >= 19.3.1
extras = test
commands_pre = dbt deps --project-dir {toxinidir}/docs/source/_static/dbt_project --profiles-dir {toxinidir}/docs/source/_static/dbt_project
Expand Down
27 changes: 24 additions & 3 deletions src/pytest_dbt_core/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from dbt.context import providers
from dbt.contracts.graph.manifest import Manifest
from dbt.parser.manifest import ManifestLoader
from dbt.semver import VersionSpecifier
from dbt.tracking import User

from dbt.adapters.factory import ( # isort:skip
Expand All @@ -28,6 +27,15 @@
dbt.tracking.active_user = User(os.getcwd())


def _get_installed_dbt_version() -> tuple[int, int]:
"""Cast a dbt version to a tuple with major and minor version."""
installed_dbt_version = version.get_installed_version()
return int(installed_dbt_version.major), int(installed_dbt_version.minor)


DBT_INSTALLED_VERSION = _get_installed_dbt_version()


@dataclasses.dataclass(frozen=True)
class Args:
"""
Expand All @@ -47,6 +55,8 @@ class Args:
target: str | None
profile: str | None
threads: int | None
# Required from dbt version 1.8 onwards
REQUIRE_RESOURCE_NAMES_WITHOUT_SPACES = False


@pytest.fixture
Expand Down Expand Up @@ -74,7 +84,7 @@ def config(request: SubRequest) -> RuntimeConfig:
threads=None,
)

if VersionSpecifier("1", "5", "12") < version.get_installed_version():
if DBT_INSTALLED_VERSION > (1, 5):
# See https://github.com/dbt-labs/dbt-core/issues/9183
project_flags = project.read_project_flags(
args.project_dir, args.profiles_dir
Expand Down Expand Up @@ -102,7 +112,12 @@ def adapter(config: RuntimeConfig) -> AdapterContainer:
AdapterContainer
The adapter.
"""
register_adapter(config)
if DBT_INSTALLED_VERSION > (1, 7):
from dbt.mp_context import get_mp_context

register_adapter(config, get_mp_context())
else:
register_adapter(config)
adapter = get_adapter(config)
adapter.acquire_connection()
return adapter
Expand All @@ -125,6 +140,12 @@ def manifest(
Manifest
The manifest.
"""
if DBT_INSTALLED_VERSION > (1, 7):
from dbt_common.clients.system import get_env
from dbt_common.context import set_invocation_context

set_invocation_context(get_env())

manifest = ManifestLoader.get_full_manifest(adapter.config)
return manifest

Expand Down
Loading