From 9b3a17baf791ccfaef48ea4aa7e07d3079fd00e1 Mon Sep 17 00:00:00 2001 From: Gerda Shank Date: Thu, 27 Jan 2022 13:40:45 -0500 Subject: [PATCH] Remove unneeded DateTimeSerialization class. Remove separate node_info in the event dictionary and leave it in the event data dictionary. Bump log version to 2. --- core/dbt/events/functions.py | 8 +------- core/dbt/events/serialization.py | 22 ++++------------------ core/dbt/events/types.py | 1 + test/interop/log_parsing/src/main.rs | 3 +-- 4 files changed, 7 insertions(+), 27 deletions(-) diff --git a/core/dbt/events/functions.py b/core/dbt/events/functions.py index 9beaaa36170..fa255a91ac0 100644 --- a/core/dbt/events/functions.py +++ b/core/dbt/events/functions.py @@ -22,7 +22,7 @@ from collections import deque global LOG_VERSION -LOG_VERSION = 1 +LOG_VERSION = 2 # create the global event history buffer with the default max size (10k) # python 3.7 doesn't support type hints on globals, but mypy requires them. hence the ignore. @@ -157,7 +157,6 @@ def event_to_serializable_dict( e: T_Event, ) -> Dict[str, Any]: - node_info: Dict[str, Any] = dict() log_line = dict() code: str try: @@ -172,10 +171,6 @@ def event_to_serializable_dict( if 'code' in log_line: del log_line['code'] - # We could just leave the 'node_info' in the data field instead - if 'node_info' in log_line and log_line['node_info']: - node_info = log_line['node_info'].pop() - event_dict = { 'type': 'log_line', 'log_version': LOG_VERSION, @@ -186,7 +181,6 @@ def event_to_serializable_dict( 'data': log_line, 'invocation_id': e.get_invocation_id(), 'thread_name': e.get_thread_name(), - 'node_info': node_info, 'code': e.code } diff --git a/core/dbt/events/serialization.py b/core/dbt/events/serialization.py index da3d7298f4d..d1f2e0b541e 100644 --- a/core/dbt/events/serialization.py +++ b/core/dbt/events/serialization.py @@ -3,11 +3,12 @@ BaseConfig as MashBaseConfig ) from mashumaro.types import SerializationStrategy -from datetime import datetime -from dateutil.parser import parse -from typing import cast +# The dbtClassMixin serialization class has a DateTime serialization strategy +# class. If a datetime ends up in an event class, we could use a similar class +# here to serialize it in our preferred format. + class ExceptionSerialization(SerializationStrategy): def serialize(self, value): out = str(value) @@ -17,20 +18,6 @@ def deserialize(self, value): return (Exception(value)) -class DateTimeSerialization(SerializationStrategy): - def serialize(self, value): - out = value.isoformat() - # Assume UTC if timezone is missing - if value.tzinfo is None: - out += "Z" - return out - - def deserialize(self, value): - return ( - value if isinstance(value, datetime) else parse(cast(str, value)) - ) - - class BaseExceptionSerialization(SerializationStrategy): def serialize(self, value): return str(value) @@ -47,6 +34,5 @@ class EventSerialization(DataClassDictMixin): class Config(MashBaseConfig): serialization_strategy = { Exception: ExceptionSerialization(), - datetime: DateTimeSerialization(), BaseException: ExceptionSerialization(), } diff --git a/core/dbt/events/types.py b/core/dbt/events/types.py index f6fc291c7d2..f153162f11f 100644 --- a/core/dbt/events/types.py +++ b/core/dbt/events/types.py @@ -2050,6 +2050,7 @@ def message(self) -> str: @dataclass class NodeFinished(DebugLevel, NodeInfo): unique_id: str + # The following isn't a RunResult class because we run into circular imports run_result: Dict[str, Any] code: str = "Q024" diff --git a/test/interop/log_parsing/src/main.rs b/test/interop/log_parsing/src/main.rs index 94231fe76b7..72985cff73b 100644 --- a/test/interop/log_parsing/src/main.rs +++ b/test/interop/log_parsing/src/main.rs @@ -69,7 +69,6 @@ struct LogLine { invocation_id: String, thread_name: String, data: serde_json::Value, // TODO be more specific - node_info: serde_json::Value, // TODO be more specific } impl ValueTest for LogLine { @@ -239,7 +238,7 @@ fn test_deserialize_serialize_is_unchanged(lines: &[String]) { mod tests { use crate::*; - const LOG_LINE: &str = r#"{"code": "Z023", "data": {"stats": {"error": 0, "pass": 3, "skip": 0, "total": 3, "warn": 0}}, "invocation_id": "f1e1557c-4f9d-4053-bb50-572cbbf2ca64", "level": "info", "log_version": 1, "msg": "Done. PASS=3 WARN=0 ERROR=0 SKIP=0 TOTAL=3", "node_info": {}, "pid": 75854, "thread_name": "MainThread", "ts": "2021-12-03T01:32:38.334601Z", "type": "log_line"}"#; + const LOG_LINE: &str = r#"{"code": "Z023", "data": {"stats": {"error": 0, "pass": 3, "skip": 0, "total": 3, "warn": 0}}, "invocation_id": "f1e1557c-4f9d-4053-bb50-572cbbf2ca64", "level": "info", "log_version": 1, "msg": "Done. PASS=3 WARN=0 ERROR=0 SKIP=0 TOTAL=3", "pid": 75854, "thread_name": "MainThread", "ts": "2021-12-03T01:32:38.334601Z", "type": "log_line"}"#; #[test] fn test_basic_loop() {