-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(targets): Safely skip parsing record field as date-time if it is …
…missing in schema (#1844)
- Loading branch information
1 parent
fe7d7d6
commit bfb7baa
Showing
3 changed files
with
49 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from __future__ import annotations | ||
|
||
import datetime | ||
|
||
from tests.conftest import BatchSinkMock, TargetMock | ||
|
||
|
||
def test_validate_record(): | ||
target = TargetMock() | ||
sink = BatchSinkMock( | ||
target, | ||
"users", | ||
{ | ||
"type": "object", | ||
"properties": { | ||
"id": {"type": "integer"}, | ||
"created_at": {"type": "string", "format": "date-time"}, | ||
"invalid_datetime": {"type": "string", "format": "date-time"}, | ||
}, | ||
}, | ||
["id"], | ||
) | ||
|
||
record = { | ||
"id": 1, | ||
"created_at": "2021-01-01T00:00:00+00:00", | ||
"missing_datetime": "2021-01-01T00:00:00+00:00", | ||
"invalid_datetime": "not a datetime", | ||
} | ||
updated_record = sink._validate_and_parse(record) | ||
|
||
assert updated_record["created_at"] == datetime.datetime( | ||
2021, | ||
1, | ||
1, | ||
0, | ||
0, | ||
tzinfo=datetime.timezone.utc, | ||
) | ||
assert updated_record["missing_datetime"] == "2021-01-01T00:00:00+00:00" | ||
assert updated_record["invalid_datetime"] == "9999-12-31 23:59:59.999999" |