Skip to content

Commit c43cf7f

Browse files
authored
Support dbt-core version 1.4 with dbt log_version 3 (#29)
1 parent ed6a7ca commit c43cf7f

File tree

5 files changed

+48
-8
lines changed

5 files changed

+48
-8
lines changed

.github/workflows/test.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,16 @@ jobs:
3131
matrix:
3232
os: [ubuntu-latest, macos-latest, windows-latest]
3333
python-version: ['3.7', '3.10']
34-
dbt-version: [0.18.x, 0.19.x, 1.x]
34+
dbt-version: [0.18.x, 0.19.x, 1.1.x, 1.4.x]
3535
exclude:
3636
- python-version: '3.10'
3737
dbt-version: 0.18.x
3838
- python-version: '3.10'
3939
dbt-version: 0.19.x
40+
- python-version: '3.7'
41+
dbt-version: 1.1.x
42+
- python-version: '3.7'
43+
dbt-version: 1.4.x
4044
steps:
4145
- uses: actions/checkout@v3
4246
- name: Set up Python ${{ matrix.python-version }}

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@ dbt-invoke properties.delete <options>
216216
- This may be partially remedied by increasing the value of the `--threads`
217217
option in `dbt-invoke properties.update`.
218218
- dbt-invoke is tested against:
219-
- Python 3.7 and 3.10
220-
- dbt 0.18, 0.19, and 1.1
219+
- dbt 0.18, 0.19, 1.1, and 1.4
221220
- macos-latest, windows-latest, ubuntu-latest
222221
- dbt-invoke has not been tested across different types of data warehouses.

dbt_invoke/properties.py

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -780,19 +780,49 @@ def _get_columns(ctx, resource_location, resource_dict, **kwargs):
780780
ctx, _MACRO_NAME, hide=True, logger=_LOGGER, sql=sql, **kwargs
781781
)
782782

783-
# from dbt-core v1.0.0 onwards, run_operations INFO logs have code M011 and messages have key 'msg'
784-
# https://github.com/dbt-labs/dbt-core/blob/22b1a09aa218e8152b0c2dd261abe2503ea15ddb/core/dbt/events/types.py#L401
785783
relevant_lines = list(
786-
filter(lambda x: x.get('code') == 'M011', result_lines)
784+
filter(
785+
lambda x: x.get(
786+
# dbt-core>=1.0,<1.4
787+
# run-operation logs contain structure
788+
# {
789+
# 'code': 'M011',
790+
# 'msg': ['column1', 'column2', ...]
791+
# }
792+
'code',
793+
# dbt-core>=1.4
794+
# run-operation logs contain structure
795+
# {
796+
# 'info': {
797+
# 'code': 'M011',
798+
# 'msg': "['column1', 'column2', ...]" # string value
799+
# }
800+
# }
801+
x.get('info', dict()).get('code'),
802+
)
803+
== 'M011',
804+
result_lines,
805+
)
787806
)
788807
if len(relevant_lines) >= 1:
789-
columns = relevant_lines[-1].get('msg')
808+
relevant_line = relevant_lines[-1]
809+
columns = relevant_line.get(
810+
'msg',
811+
relevant_line.get('info', dict()).get('msg'),
812+
)
790813
else:
791814
# for older dbt-core versions, we need to cross fingers a little harder
792815
relevant_lines = result_lines[1:]
793816
# also, the message key is different
794817
columns = relevant_lines[-1].get('message')
795-
# columns are not passed as valid json but as a string representation of a list
818+
# In some version of dbt columns are not passed as valid json but as
819+
# a string representation of a list
820+
is_string_list = (
821+
isinstance(columns, str)
822+
and columns.startswith('[')
823+
and columns.endswith(']')
824+
)
825+
if is_string_list:
796826
columns = ast.literal_eval(columns)
797827
return columns
798828

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
agate>=1.6,<1.7.1
2+
dbt-core~=1.4.0
3+
dbt-sqlite~=1.4.0
4+
invoke>=1.4.1
5+
PyYAML>=5.1
6+
ruamel.yaml>=0.17.12
7+
-e .

0 commit comments

Comments
 (0)