Skip to content

Commit

Permalink
Make json default for dbt ls, do not rerun dbt ls unnecessarily
Browse files Browse the repository at this point in the history
Signed-off-by: Robert Astel <rob.astel@gmail.com>
  • Loading branch information
robastel committed Jan 2, 2022
1 parent 672067d commit aeff664
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion dbt_invoke/internal/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def dbt_ls(
ctx,
supported_resource_types=None,
hide=True,
output='path',
output='json',
logger=None,
**kwargs,
):
Expand Down
22 changes: 12 additions & 10 deletions dbt_invoke/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ def _transform_ls_results(ctx, **kwargs):
output='json',
**kwargs,
)
potential_result_paths = None
results = dict()
for i, potential_result in enumerate(potential_results):
if 'original_file_path' in potential_result:
Expand All @@ -274,16 +275,17 @@ def _transform_ls_results(ctx, **kwargs):
# versions of dbt, we need to run "dbt ls" with the
# "--output path" argument in order to retrieve paths
else:
potential_result_paths = _utils.dbt_ls(
ctx,
supported_resource_types=_SUPPORTED_RESOURCE_TYPES,
logger=_LOGGER,
output='path',
**kwargs,
)
assert len(potential_result_paths) == len(
potential_results
), 'Length of results differs from length of result details'
if potential_result_paths is None:
potential_result_paths = _utils.dbt_ls(
ctx,
supported_resource_types=_SUPPORTED_RESOURCE_TYPES,
logger=_LOGGER,
output='path',
**kwargs,
)
assert len(potential_result_paths) == len(
potential_results
), 'Length of results differs from length of result details'
potential_result_path = potential_result_paths[i]
if Path(ctx.config['project_path'], potential_result_path).exists():
results[potential_result_path] = potential_result
Expand Down
1 change: 1 addition & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def test_dbt_ls(self):
project_dir=self.project_dir,
profiles_dir=self.profiles_dir,
supported_resource_types=SUPPORTED_RESOURCE_TYPES,
output='path',
logger=self.logger,
**dbt_ls_kwargs,
)
Expand Down

0 comments on commit aeff664

Please sign in to comment.