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

Use function for datetime in CommandCompleted and throw error when testing #7217

Merged
merged 2 commits into from
Mar 24, 2023

Conversation

gshank
Copy link
Contributor

@gshank gshank commented Mar 23, 2023

Description

Use utility function "get_json_string_utcnow" to set the time in the CommandCompleted message. Throw errors when testing and unable to parse the kwarg dictionary in the logging event base class.

Checklist

@gshank gshank added the Skip Changelog Skips GHA to check for changelog file label Mar 23, 2023
@gshank gshank requested review from a team as code owners March 23, 2023 18:12
@cla-bot cla-bot bot added the cla:yes label Mar 23, 2023
Comment on lines +78 to +83
# If we're testing throw an error so that we notice failures
if "pytest" in sys.modules:
raise Exception(error_msg)
else:
fire_event(Note(msg=error_msg))
self.pb_msg = msg_cls()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah! this is good!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this also mean that "fire a warning instead of raising an exception on event serialization errors" was effectively resolved by the proto changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, probably, but mainly because the google protobuf messages are more strongly typed, so that errors are caught here instead of on serialization. As a belt-and-suspenders thing it's probably not a bad idea to catch on serialization too (though I haven't actually seen any errors there).

self.pb_msg = msg_cls()
error_msg = f"[{class_name}]: Unable to parse dict {kwargs}"
# If we're testing throw an error so that we notice failures
if "pytest" in sys.modules:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can just error on this warning in Pytest instead of having branching logic.

https://docs.pytest.org/en/latest/how-to/capture-warnings.html

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that we want to issue warnings when users are running dbt though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I think most people are in the habit of just ignoring those pytest warnings, and we certainly aren't going to see them in Ci runs, so we still wouldn't necessarily notice that we have a logging event with invalid types.

Copy link
Member

@aranke aranke Mar 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that we want to issue warnings when users are running dbt though.

This doesn't affect users unless they're running Pytest.

we certainly aren't going to see them in Ci runs

If you promote a warning to an error in Pytest, people will notice :)

@gshank gshank merged commit f573870 into main Mar 24, 2023
@gshank gshank deleted the fix_command_completed branch March 24, 2023 14:52
@jtcohen6 jtcohen6 mentioned this pull request Mar 27, 2023
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla:yes Skip Changelog Skips GHA to check for changelog file
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants