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

still register adapter when manifest is provided #9440

Merged
merged 3 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 4 additions & 1 deletion core/dbt/cli/requires.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import dbt.tracking
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
from dbt.flags import set_flags, get_flag_dict
from dbt.cli.exceptions import (
ExceptionExit,
Expand Down Expand Up @@ -31,6 +31,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 @@ -277,6 +278,8 @@
ctx.obj["manifest"] = parse_manifest(
runtime_config, write_perf_info, write, ctx.obj["flags"].write_json
)
else:
register_adapter(runtime_config, get_mp_context())

Check warning on line 282 in core/dbt/cli/requires.py

View check run for this annotation

Codecov / codecov/patch

core/dbt/cli/requires.py#L282

Added line #L282 was not covered by tests
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need to add:

adapter = get_adapter(runtime_config)      
adapter.set_macro_context_generator(generate_runtime_macro_context)
adapter.set_macro_resolver(ctx.obj["manifest"])

to get the tests passing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! Done!

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 @@ -70,3 +77,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
Loading