Compare commits

...

4 Commits

Author SHA1 Message Date
Jeremy Cohen
24872f1292 What should docs generate --defer really do? 2023-01-30 12:38:35 +01:00
Jeremy Cohen
83850f5121 Switch -m to -s 2023-01-30 12:38:09 +01:00
Github Build Bot
f368719760 Add generated CLI API docs 2023-01-28 07:15:18 +00:00
Chenyu Li
465ad21997 move favor state arg to click 2023-01-27 23:10:19 -08:00
8 changed files with 62 additions and 16 deletions

View File

@@ -101,6 +101,7 @@ def cli(ctx, **kwargs):
@cli.command("build") @cli.command("build")
@click.pass_context @click.pass_context
@p.defer @p.defer
@p.favor_defer_state
@p.exclude @p.exclude
@p.fail_fast @p.fail_fast
@p.full_refresh @p.full_refresh
@@ -169,6 +170,7 @@ def docs(ctx, **kwargs):
@click.pass_context @click.pass_context
@p.compile_docs @p.compile_docs
@p.defer @p.defer
@p.favor_defer_state
@p.exclude @p.exclude
@p.models @p.models
@p.profile @p.profile
@@ -232,6 +234,7 @@ def docs_serve(ctx, **kwargs):
@cli.command("compile") @cli.command("compile")
@click.pass_context @click.pass_context
@p.defer @p.defer
@p.favor_defer_state
@p.exclude @p.exclude
@p.full_refresh @p.full_refresh
@p.models @p.models
@@ -401,6 +404,7 @@ def parse(ctx, **kwargs):
@cli.command("run") @cli.command("run")
@click.pass_context @click.pass_context
@p.defer @p.defer
@p.favor_defer_state
@p.exclude @p.exclude
@p.fail_fast @p.fail_fast
@p.full_refresh @p.full_refresh
@@ -502,6 +506,7 @@ def seed(ctx, **kwargs):
@cli.command("snapshot") @cli.command("snapshot")
@click.pass_context @click.pass_context
@p.defer @p.defer
@p.favor_defer_state
@p.exclude @p.exclude
@p.models @p.models
@p.profile @p.profile
@@ -581,6 +586,7 @@ cli.commands["source"].add_command(snapshot_freshness, "snapshot-freshness") #
@cli.command("test") @cli.command("test")
@click.pass_context @click.pass_context
@p.defer @p.defer
@p.favor_defer_state
@p.exclude @p.exclude
@p.fail_fast @p.fail_fast
@p.indirect_selection @p.indirect_selection

View File

@@ -75,6 +75,13 @@ defer = click.option(
help="If set, defer to the state variable for resolving unselected nodes.", help="If set, defer to the state variable for resolving unselected nodes.",
) )
favor_defer_state = click.option(
"--favor-state/--no-favor-state",
envvar="DBT_FAVOR_STATE",
help="If favor state, defer to the state variable for resolving unselected nodes, even if node exist as a database object in the current environment. Otherwise expect standard defer behavior",
)
enable_legacy_logger = click.option( enable_legacy_logger = click.option(
"--enable-legacy-logger/--no-enable-legacy-logger", "--enable-legacy-logger/--no-enable-legacy-logger",
envvar="DBT_ENABLE_LEGACY_LOGGER", envvar="DBT_ENABLE_LEGACY_LOGGER",

Binary file not shown.

Binary file not shown.

View File

@@ -66,6 +66,11 @@
<p>Type: boolean</p> <p>Type: boolean</p>
<p>If set, defer to the state variable for resolving unselected nodes.</p> <p>If set, defer to the state variable for resolving unselected nodes.</p>
</section> </section>
<section id="build|favor_state">
<h4>favor_state<a class="headerlink" href="#build|favor_state" title="Permalink to this heading"></a></h4>
<p>Type: boolean</p>
<p>If favor state, defer to the state variable for resolving unselected nodes, even if node exist as a database object in the current environment. Otherwise expect standard defer behavior</p>
</section>
<section id="build|exclude"> <section id="build|exclude">
<h4>exclude<a class="headerlink" href="#build|exclude" title="Permalink to this heading"></a></h4> <h4>exclude<a class="headerlink" href="#build|exclude" title="Permalink to this heading"></a></h4>
<p>Type: unknown</p> <p>Type: unknown</p>
@@ -83,7 +88,7 @@
</section> </section>
<section id="build|indirect_selection"> <section id="build|indirect_selection">
<h4>indirect_selection<a class="headerlink" href="#build|indirect_selection" title="Permalink to this heading"></a></h4> <h4>indirect_selection<a class="headerlink" href="#build|indirect_selection" title="Permalink to this heading"></a></h4>
<p>Type: choice: [eager, cautious]</p> <p>Type: choice: [eager, cautious, buildable]</p>
<p>Select all tests that are adjacent to selected resources, even if they those resources have been explicitly selected.</p> <p>Select all tests that are adjacent to selected resources, even if they those resources have been explicitly selected.</p>
</section> </section>
<section id="build|profile"> <section id="build|profile">
@@ -188,6 +193,11 @@
<p>Type: boolean</p> <p>Type: boolean</p>
<p>If set, defer to the state variable for resolving unselected nodes.</p> <p>If set, defer to the state variable for resolving unselected nodes.</p>
</section> </section>
<section id="compile|favor_state">
<h4>favor_state<a class="headerlink" href="#compile|favor_state" title="Permalink to this heading"></a></h4>
<p>Type: boolean</p>
<p>If favor state, defer to the state variable for resolving unselected nodes, even if node exist as a database object in the current environment. Otherwise expect standard defer behavior</p>
</section>
<section id="compile|exclude"> <section id="compile|exclude">
<h4>exclude<a class="headerlink" href="#compile|exclude" title="Permalink to this heading"></a></h4> <h4>exclude<a class="headerlink" href="#compile|exclude" title="Permalink to this heading"></a></h4>
<p>Type: unknown</p> <p>Type: unknown</p>
@@ -349,7 +359,7 @@
<section id="init|skip_profile_setup"> <section id="init|skip_profile_setup">
<h4>skip_profile_setup<a class="headerlink" href="#init|skip_profile_setup" title="Permalink to this heading"></a></h4> <h4>skip_profile_setup<a class="headerlink" href="#init|skip_profile_setup" title="Permalink to this heading"></a></h4>
<p>Type: boolean</p> <p>Type: boolean</p>
<p>Skip interative profile setup.</p> <p>Skip interactive profile setup.</p>
</section> </section>
<section id="init|target"> <section id="init|target">
<h4>target<a class="headerlink" href="#init|target" title="Permalink to this heading"></a></h4> <h4>target<a class="headerlink" href="#init|target" title="Permalink to this heading"></a></h4>
@@ -369,7 +379,7 @@
</section> </section>
<section id="list|indirect_selection"> <section id="list|indirect_selection">
<h4>indirect_selection<a class="headerlink" href="#list|indirect_selection" title="Permalink to this heading"></a></h4> <h4>indirect_selection<a class="headerlink" href="#list|indirect_selection" title="Permalink to this heading"></a></h4>
<p>Type: choice: [eager, cautious]</p> <p>Type: choice: [eager, cautious, buildable]</p>
<p>Select all tests that are adjacent to selected resources, even if they those resources have been explicitly selected.</p> <p>Select all tests that are adjacent to selected resources, even if they those resources have been explicitly selected.</p>
</section> </section>
<section id="list|models"> <section id="list|models">
@@ -440,7 +450,7 @@
</section> </section>
<section id="list|indirect_selection"> <section id="list|indirect_selection">
<h4>indirect_selection<a class="headerlink" href="#list|indirect_selection" title="Permalink to this heading"></a></h4> <h4>indirect_selection<a class="headerlink" href="#list|indirect_selection" title="Permalink to this heading"></a></h4>
<p>Type: choice: [eager, cautious]</p> <p>Type: choice: [eager, cautious, buildable]</p>
<p>Select all tests that are adjacent to selected resources, even if they those resources have been explicitly selected.</p> <p>Select all tests that are adjacent to selected resources, even if they those resources have been explicitly selected.</p>
</section> </section>
<section id="list|models"> <section id="list|models">
@@ -560,6 +570,11 @@
<p>Type: boolean</p> <p>Type: boolean</p>
<p>If set, defer to the state variable for resolving unselected nodes.</p> <p>If set, defer to the state variable for resolving unselected nodes.</p>
</section> </section>
<section id="run|favor_state">
<h4>favor_state<a class="headerlink" href="#run|favor_state" title="Permalink to this heading"></a></h4>
<p>Type: boolean</p>
<p>If favor state, defer to the state variable for resolving unselected nodes, even if node exist as a database object in the current environment. Otherwise expect standard defer behavior</p>
</section>
<section id="run|exclude"> <section id="run|exclude">
<h4>exclude<a class="headerlink" href="#run|exclude" title="Permalink to this heading"></a></h4> <h4>exclude<a class="headerlink" href="#run|exclude" title="Permalink to this heading"></a></h4>
<p>Type: unknown</p> <p>Type: unknown</p>
@@ -752,6 +767,11 @@
<p>Type: boolean</p> <p>Type: boolean</p>
<p>If set, defer to the state variable for resolving unselected nodes.</p> <p>If set, defer to the state variable for resolving unselected nodes.</p>
</section> </section>
<section id="snapshot|favor_state">
<h4>favor_state<a class="headerlink" href="#snapshot|favor_state" title="Permalink to this heading"></a></h4>
<p>Type: boolean</p>
<p>If favor state, defer to the state variable for resolving unselected nodes, even if node exist as a database object in the current environment. Otherwise expect standard defer behavior</p>
</section>
<section id="snapshot|exclude"> <section id="snapshot|exclude">
<h4>exclude<a class="headerlink" href="#snapshot|exclude" title="Permalink to this heading"></a></h4> <h4>exclude<a class="headerlink" href="#snapshot|exclude" title="Permalink to this heading"></a></h4>
<p>Type: unknown</p> <p>Type: unknown</p>
@@ -814,6 +834,11 @@
<p>Type: boolean</p> <p>Type: boolean</p>
<p>If set, defer to the state variable for resolving unselected nodes.</p> <p>If set, defer to the state variable for resolving unselected nodes.</p>
</section> </section>
<section id="test|favor_state">
<h4>favor_state<a class="headerlink" href="#test|favor_state" title="Permalink to this heading"></a></h4>
<p>Type: boolean</p>
<p>If favor state, defer to the state variable for resolving unselected nodes, even if node exist as a database object in the current environment. Otherwise expect standard defer behavior</p>
</section>
<section id="test|exclude"> <section id="test|exclude">
<h4>exclude<a class="headerlink" href="#test|exclude" title="Permalink to this heading"></a></h4> <h4>exclude<a class="headerlink" href="#test|exclude" title="Permalink to this heading"></a></h4>
<p>Type: unknown</p> <p>Type: unknown</p>
@@ -826,7 +851,7 @@
</section> </section>
<section id="test|indirect_selection"> <section id="test|indirect_selection">
<h4>indirect_selection<a class="headerlink" href="#test|indirect_selection" title="Permalink to this heading"></a></h4> <h4>indirect_selection<a class="headerlink" href="#test|indirect_selection" title="Permalink to this heading"></a></h4>
<p>Type: choice: [eager, cautious]</p> <p>Type: choice: [eager, cautious, buildable]</p>
<p>Select all tests that are adjacent to selected resources, even if they those resources have been explicitly selected.</p> <p>Select all tests that are adjacent to selected resources, even if they those resources have been explicitly selected.</p>
</section> </section>
<section id="test|models"> <section id="test|models">

File diff suppressed because one or more lines are too long

View File

@@ -1,7 +1,7 @@
import os import os
import shutil import shutil
from datetime import datetime from datetime import datetime
from typing import Dict, List, Any, Optional, Tuple, Set from typing import Dict, List, Any, Optional, Tuple, Set, AbstractSet
from dbt.dataclass_schema import ValidationError from dbt.dataclass_schema import ValidationError
@@ -229,6 +229,13 @@ class GenerateTask(CompileTask):
adapter = get_adapter(self.config) adapter = get_adapter(self.config)
with adapter.connection_named("generate_catalog"): with adapter.connection_named("generate_catalog"):
if self.args.defer:
# Look up catalog entries only on the basis of whether they exist in the
# target schema, ignoring selection logic passed to `docs generate` -> `compile`
# Unfortunately, this requires running caching queries again,
# even though we may have just run them during CompileTask.run()
self.populate_adapter_cache(adapter)
self.defer_to_manifest(adapter, selected_uids=set())
fire_event(BuildingCatalog()) fire_event(BuildingCatalog())
catalog_table, exceptions = adapter.get_catalog(self.manifest) catalog_table, exceptions = adapter.get_catalog(self.manifest)

View File

@@ -6,6 +6,7 @@ from copy import deepcopy
import pytest import pytest
from dbt.tests.util import run_dbt, write_file, rm_file from dbt.tests.util import run_dbt, write_file, rm_file
from dbt.cli.main import dbtUsageException
from dbt.exceptions import DbtRuntimeError from dbt.exceptions import DbtRuntimeError
@@ -98,7 +99,7 @@ class BaseDeferState:
class TestDeferStateUnsupportedCommands(BaseDeferState): class TestDeferStateUnsupportedCommands(BaseDeferState):
def test_unsupported_commands(self, project): def test_unsupported_commands(self, project):
# make sure these commands don"t work with --defer # make sure these commands don"t work with --defer
with pytest.raises(SystemExit): with pytest.raises(dbtUsageException):
run_dbt(["seed", "--defer"]) run_dbt(["seed", "--defer"])
def test_no_state(self, project): def test_no_state(self, project):
@@ -149,7 +150,7 @@ class TestRunDeferState(BaseDeferState):
# defer test, it succeeds # defer test, it succeeds
results = run_dbt( results = run_dbt(
["test", "-m", "view_model+", "--state", "state", "--defer", "--target", "otherschema"] ["test", "-s", "view_model+", "--state", "state", "--defer", "--target", "otherschema"]
) )
# defer docs generate with state, catalog refers schema from the happy times # defer docs generate with state, catalog refers schema from the happy times
@@ -157,7 +158,7 @@ class TestRunDeferState(BaseDeferState):
[ [
"docs", "docs",
"generate", "generate",
"-m", "-s",
"view_model+", "view_model+",
"--state", "--state",
"state", "state",
@@ -171,7 +172,7 @@ class TestRunDeferState(BaseDeferState):
# with state it should work though # with state it should work though
results = run_dbt( results = run_dbt(
["run", "-m", "view_model", "--state", "state", "--defer", "--target", "otherschema"] ["run", "-s", "view_model", "--state", "state", "--defer", "--target", "otherschema"]
) )
assert other_schema not in results[0].node.compiled_code assert other_schema not in results[0].node.compiled_code
assert unique_schema in results[0].node.compiled_code assert unique_schema in results[0].node.compiled_code
@@ -192,12 +193,12 @@ class TestRunDeferStateChangedModel(BaseDeferState):
# the sql here is just wrong, so it should fail # the sql here is just wrong, so it should fail
run_dbt( run_dbt(
["run", "-m", "view_model", "--state", "state", "--defer", "--target", "otherschema"], ["run", "-s", "view_model", "--state", "state", "--defer", "--target", "otherschema"],
expect_pass=False, expect_pass=False,
) )
# but this should work since we just use the old happy model # but this should work since we just use the old happy model
run_dbt( run_dbt(
["run", "-m", "table_model", "--state", "state", "--defer", "--target", "otherschema"], ["run", "-s", "table_model", "--state", "state", "--defer", "--target", "otherschema"],
expect_pass=True, expect_pass=True,
) )
@@ -206,7 +207,7 @@ class TestRunDeferStateChangedModel(BaseDeferState):
# this should fail because the table model refs a broken ephemeral # this should fail because the table model refs a broken ephemeral
# model, which it should see # model, which it should see
run_dbt( run_dbt(
["run", "-m", "table_model", "--state", "state", "--defer", "--target", "otherschema"], ["run", "-s", "table_model", "--state", "state", "--defer", "--target", "otherschema"],
expect_pass=False, expect_pass=False,
) )
@@ -246,7 +247,7 @@ class TestDeferStateDeletedUpstream(BaseDeferState):
# ephemeral_model is now gone. previously this caused a # ephemeral_model is now gone. previously this caused a
# keyerror (dbt#2875), now it should pass # keyerror (dbt#2875), now it should pass
run_dbt( run_dbt(
["run", "-m", "view_model", "--state", "state", "--defer", "--target", "otherschema"], ["run", "-s", "view_model", "--state", "state", "--defer", "--target", "otherschema"],
expect_pass=True, expect_pass=True,
) )
@@ -258,7 +259,7 @@ class TestDeferStateDeletedUpstream(BaseDeferState):
run_dbt( run_dbt(
[ [
"run", "run",
"-m", "-s",
"view_model", "view_model",
"--state", "--state",
"state", "state",