-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Add invocation_args_dict to ProviderContext #5782
Add invocation_args_dict to ProviderContext #5782
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
@gshank the Structured Logging Schema check failed but the integration tests pass when I run them locally. I was looking into using --log-format-json in the test itself:
And then running the assert on the parsed_logs list of dicts. What are your thoughts on this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work @jared-rimmer! Just a teensy comment about naming, and one about fixing the failing test. Could you also create a changelog entry?
def test_builtin_invocation_args_dict_function(self, project): | ||
_, log_output = run_dbt_and_capture( | ||
[ | ||
"--debug", | ||
"--log-format=json", | ||
"run-operation", | ||
"validate_invocation", | ||
"--args", | ||
"{my_variable: test_variable}", | ||
] | ||
) | ||
|
||
parsed_logs = [] | ||
for line in log_output.split("\n"): | ||
try: | ||
log = json.loads(line) | ||
except ValueError: | ||
continue | ||
|
||
parsed_logs.append(log) | ||
|
||
# Value of msg is a string | ||
result = next( | ||
( | ||
item | ||
for item in parsed_logs | ||
if "invocation_result" in item["data"].get("msg", "msg") | ||
), | ||
False, | ||
) | ||
|
||
assert result | ||
|
||
# Result is checked in two parts because profiles_dir is unique each test run | ||
expected = "invocation_result: {'debug': True, 'log_format': 'json', 'write_json': True, 'use_colors': True, 'printer_width': 80, 'version_check': True, 'partial_parse': True, 'static_parser': True, 'profiles_dir': " | ||
assert expected in str(result) | ||
|
||
expected = "'send_anonymous_usage_stats': False, 'event_buffer_size': 100000, 'quiet': False, 'no_print': False, 'macro': 'validate_invocation', 'args': '{my_variable: test_variable}', 'which': 'run-operation', 'rpc_method': 'run-operation', 'indirect_selection': 'eager'}" | ||
assert expected in str(result) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I opted to add --log-format=json
to the dbt method and parse the json logs then implement the asserts on this within the test rather than having it in the macro jinja.
Based on similar logic I found in test_query_comments
* Add invocation_args_to_dict to ProviderContext * Change invocation_args_to_dict contextproperty to invocation_args_dict * Fix invocation_args_dict builtin test * Add CHANGELOG entry * Fix formatting
resolves #5524
Description
invocation_args_dict
contextproperty to the ProviderContext class.test_context.py
using a MacroContexttest_builtin_functions
that prints {{invocation_args_dict}} to the logs. Again using a MacroContextChecklist
changie new
to create a changelog entry