Skip to content

Commit

Permalink
fix(dbt Cloud): allow passing job ID (#264)
Browse files Browse the repository at this point in the history
  • Loading branch information
betodealmeida authored Feb 28, 2024
1 parent 0549abe commit 235ebf6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/preset_cli/cli/superset/sync/dbt/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,14 @@ def get_account_id(client: DBTClient) -> int:
click.echo(click.style("No accounts available", fg="bright_red"))
sys.exit(1)
if len(accounts) == 1:
return accounts[0]["id"]
account = accounts[0]
click.echo(
f'Using account {account["name"]} [id={account["id"]}] since it\'s the only one',
)
return account["id"]
click.echo("Choose an account:")
for i, account in enumerate(accounts):
click.echo(f'({i+1}) {account["name"]}')
click.echo(f'({i+1}) {account["name"]} [id={account["id"]}]')

while True:
try:
Expand All @@ -279,7 +283,7 @@ def get_project_id(client: DBTClient, account_id: Optional[int] = None) -> int:
return projects[0]["id"]
click.echo("Choose a project:")
for i, project in enumerate(projects):
click.echo(f'({i+1}) {project["name"]}')
click.echo(f'({i+1}) {project["name"]} [id={project["id"]}]')

while True:
try:
Expand Down Expand Up @@ -316,7 +320,7 @@ def get_job(

click.echo("Choose a job:")
for i, job in enumerate(jobs):
click.echo(f'({i+1}) {job["name"]}')
click.echo(f'({i+1}) {job["name"]} [id={job["id"]}]')

while True:
try:
Expand Down Expand Up @@ -373,6 +377,8 @@ def process_sl_metrics(

@click.command()
@click.argument("token")
@click.argument("account_id", type=click.INT, required=False, default=None)
@click.argument("project_id", type=click.INT, required=False, default=None)
@click.argument("job_id", type=click.INT, required=False, default=None)
@click.option(
"--disallow-edits",
Expand Down Expand Up @@ -433,6 +439,8 @@ def dbt_cloud( # pylint: disable=too-many-arguments, too-many-locals
select: Tuple[str, ...],
exclude: Tuple[str, ...],
exposures: Optional[str] = None,
account_id: Optional[int] = None,
project_id: Optional[int] = None,
job_id: Optional[int] = None,
disallow_edits: bool = False,
external_url_prefix: str = "",
Expand Down Expand Up @@ -468,7 +476,7 @@ def dbt_cloud( # pylint: disable=too-many-arguments, too-many-locals
preserve_metadata = preserve_columns if preserve_columns else preserve_metadata

try:
job = get_job(dbt_client, job_id=job_id)
job = get_job(dbt_client, account_id, project_id, job_id)
except ValueError:
click.echo(click.style(f"Job {job_id} not available", fg="bright_red"))
sys.exit(2)
Expand Down
18 changes: 18 additions & 0 deletions tests/cli/superset/sync/dbt/command_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,8 @@ def test_dbt_cloud(mocker: MockerFixture) -> None:
"sync",
"dbt-cloud",
"XXX",
"1",
"2",
"123",
],
catch_exceptions=False,
Expand Down Expand Up @@ -1068,6 +1070,8 @@ def test_dbt_cloud_preserve_metadata(mocker: MockerFixture) -> None:
"sync",
"dbt-cloud",
"XXX",
"1",
"2",
"123",
"--preserve-metadata",
],
Expand Down Expand Up @@ -1121,6 +1125,8 @@ def test_dbt_cloud_preserve_columns(mocker: MockerFixture) -> None:
"sync",
"dbt-cloud",
"XXX",
"1",
"2",
"123",
"--preserve-columns",
],
Expand Down Expand Up @@ -1174,6 +1180,8 @@ def test_dbt_cloud_merge_metadata(mocker: MockerFixture) -> None:
"sync",
"dbt-cloud",
"XXX",
"1",
"2",
"123",
"--merge-metadata",
],
Expand Down Expand Up @@ -1207,6 +1215,8 @@ def test_dbt_cloud_preserve_and_merge(mocker: MockerFixture) -> None:
"sync",
"dbt-cloud",
"XXX",
"1",
"2",
"123",
"--preserve-metadata",
"--merge-metadata",
Expand Down Expand Up @@ -1424,6 +1434,8 @@ def test_dbt_cloud_no_database(mocker: MockerFixture) -> None:
"sync",
"dbt-cloud",
"XXX",
"1",
"2",
"123",
],
catch_exceptions=False,
Expand Down Expand Up @@ -1460,6 +1472,8 @@ def test_dbt_cloud_invalid_job_id(mocker: MockerFixture) -> None:
"sync",
"dbt-cloud",
"XXX",
"1",
"2",
"123",
],
catch_exceptions=False,
Expand Down Expand Up @@ -1503,6 +1517,8 @@ def test_dbt_cloud_multiple_databases(mocker: MockerFixture) -> None:
"sync",
"dbt-cloud",
"XXX",
"1",
"2",
"123",
],
catch_exceptions=False,
Expand Down Expand Up @@ -1618,6 +1634,8 @@ def test_dbt_cloud_exposures_only(mocker: MockerFixture, fs: FakeFilesystem) ->
"sync",
"dbt-cloud",
"XXX",
"1",
"2",
"123",
"--exposures",
str(exposures),
Expand Down

0 comments on commit 235ebf6

Please sign in to comment.