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

Fix microbatch dbt list --output JSON #11187

Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20250109-123309.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: Fix microbatch dbt list --output json
time: 2025-01-09T12:33:09.958795+01:00
custom:
Author: internetcoffeephone
Issue: 10556 11098
4 changes: 3 additions & 1 deletion core/dbt/task/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from dbt.node_types import NodeType
from dbt.task.base import resource_types_from_args
from dbt.task.runnable import GraphRunnableTask
from dbt.utils import JSONEncoder
from dbt_common.events.contextvars import task_contextvars
from dbt_common.events.functions import fire_event, warn_or_error
from dbt_common.events.types import PrintEvent
Expand Down Expand Up @@ -142,7 +143,8 @@ def generate_json(self):
if self.args.output_keys
else k in self.ALLOWED_KEYS
)
}
},
cls=JSONEncoder,
)

def generate_paths(self) -> Iterator[str]:
Expand Down
15 changes: 15 additions & 0 deletions tests/functional/microbatch/test_microbatch.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
from unittest import mock

import pytest
Expand All @@ -15,6 +16,7 @@
MicrobatchMacroOutsideOfBatchesDeprecation,
MicrobatchModelNoEventTimeInputs,
)
from dbt.tests.fixtures.project import TestProjInfo
from dbt.tests.util import (
get_artifact,
patch_microbatch_end_time,
Expand Down Expand Up @@ -333,6 +335,19 @@ class TestMicrobatchCLIBuild(TestMicrobatchCLI):
CLI_COMMAND_NAME = "build"


class TestMicrobatchCLIRunOutputJSON(BaseMicrobatchTest):
def test_list_output_json(self, project: TestProjInfo):
internetcoffeephone marked this conversation as resolved.
Show resolved Hide resolved
"""Test whether the command `dbt list --output json` works"""
model_catcher = EventCatcher(event_to_catch=LogModelResult)
batch_catcher = EventCatcher(event_to_catch=LogBatchResult)

_, microbatch_json = run_dbt(
["list", "--output", "json"], callbacks=[model_catcher.catch, batch_catcher.catch]
)
microbatch_dict = json.loads(microbatch_json)
assert microbatch_dict["config"]["begin"] == "2020-01-01T00:00:00"


class TestMicroBatchBoundsDefault(BaseMicrobatchTest):
def test_run_with_event_time(self, project):
# initial run -- backfills all data
Expand Down
Loading