-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#4504] Use mashumaro for logging serialization
- Loading branch information
Showing
23 changed files
with
578 additions
and
713 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from mashumaro import DataClassDictMixin | ||
from mashumaro.config import ( | ||
BaseConfig as MashBaseConfig | ||
) | ||
from mashumaro.types import SerializationStrategy | ||
from datetime import datetime | ||
from dateutil.parser import parse | ||
from typing import cast | ||
|
||
|
||
class ExceptionSerialization(SerializationStrategy): | ||
def serialize(self, value): | ||
out = str(value) | ||
return out | ||
|
||
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 dbtClassEventMixin(DataClassDictMixin): | ||
|
||
class Config(MashBaseConfig): | ||
serialization_strategy = { | ||
Exception: ExceptionSerialization(), | ||
datetime: DateTimeSerialization(), | ||
} |
Oops, something went wrong.