Skip to content

Commit

Permalink
still register adapter when manifest is provided (#9440)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChenyuLInx authored Feb 9, 2024
1 parent 581d856 commit 6f603f6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
9 changes: 8 additions & 1 deletion core/dbt/cli/requires.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from dbt_common.invocation import reset_invocation_id

from dbt.version import installed as installed_version
from dbt.adapters.factory import adapter_management
from dbt.adapters.factory import adapter_management, register_adapter, get_adapter
from dbt.context.providers import generate_runtime_macro_context
from dbt.flags import set_flags, get_flag_dict
from dbt.cli.exceptions import (
ExceptionExit,
Expand Down Expand Up @@ -35,6 +36,7 @@
from dbt.tracking import active_user, initialize_from_flags, track_run
from dbt_common.utils import cast_dict_to_dict_of_strings
from dbt.plugins import set_up_plugin_manager
from dbt.mp_context import get_mp_context

from click import Context
from functools import update_wrapper
Expand Down Expand Up @@ -283,6 +285,11 @@ def wrapper(*args, **kwargs):
ctx.obj["manifest"] = parse_manifest(
runtime_config, write_perf_info, write, ctx.obj["flags"].write_json
)
else:
register_adapter(runtime_config, get_mp_context())
adapter = get_adapter(runtime_config)
adapter.set_macro_context_generator(generate_runtime_macro_context)
adapter.set_macro_resolver(ctx.obj["manifest"])
return func(*args, **kwargs)

return update_wrapper(wrapper, func)
Expand Down
18 changes: 18 additions & 0 deletions tests/functional/dbt_runner/test_dbt_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,20 @@
from dbt.cli.exceptions import DbtUsageException
from dbt.cli.main import dbtRunner
from dbt.exceptions import DbtProjectError
from dbt.adapters.factory import reset_adapters, FACTORY


class TestDbtRunner:
@pytest.fixture
def dbt(self) -> dbtRunner:
return dbtRunner()

@pytest.fixture(scope="class")
def models(self):
return {
"models.sql": "select 1 as id",
}

def test_group_invalid_option(self, dbt: dbtRunner) -> None:
res = dbt.invoke(["--invalid-option"])
assert type(res.exception) == DbtUsageException
Expand Down Expand Up @@ -72,3 +79,14 @@ def test_invoke_kwargs_profiles_dir(self, project, dbt):
def test_invoke_kwargs_and_flags(self, project, dbt):
res = dbt.invoke(["--log-format=text", "run"], log_format="json")
assert res.result.args["log_format"] == "json"

def test_pass_in_manifest(self, project, dbt):
result = dbt.invoke(["parse"])
manifest = result.result

reset_adapters()
assert len(FACTORY.adapters) == 0
result = dbtRunner(manifest=manifest).invoke(["run"])
# Check that the adapters are registered again.
assert result.success
assert len(FACTORY.adapters) == 1

0 comments on commit 6f603f6

Please sign in to comment.