-
Notifications
You must be signed in to change notification settings - Fork 69
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
fix(targets): Safely skip parsing record field as date-time if it is missing in schema #1844
Merged
edgarrmondragon
merged 13 commits into
main
from
1836-bug-_parse_timestamps_in_record-throws-exception-for-key-not-present-in-schema
Sep 28, 2023
Merged
Changes from 8 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
3ed9f0d
fix: Safely ignore parsing record field as datetime if it is missing …
edgarrmondragon e73adff
Merge branch 'main' into 1836-bug-_parse_timestamps_in_record-throws-…
edgarrmondragon e086fe0
Merge branch 'main' into 1836-bug-_parse_timestamps_in_record-throws-…
edgarrmondragon 4c80636
Merge branch 'main' into 1836-bug-_parse_timestamps_in_record-throws-…
edgarrmondragon 23c8f2e
Merge branch 'main' into 1836-bug-_parse_timestamps_in_record-throws-…
edgarrmondragon ddec1ca
Add test
edgarrmondragon 57b15dd
Merge branch 'main' into 1836-bug-_parse_timestamps_in_record-throws-…
edgarrmondragon c85d4e1
Check if key is in schema instead of try-except inside loop
edgarrmondragon 5e6a427
Test invalid datetime
edgarrmondragon d3eb521
Merge branch 'main' into 1836-bug-_parse_timestamps_in_record-throws-…
edgarrmondragon 6fa9cf4
Simplify test
edgarrmondragon 5666995
Merge branch 'main' into 1836-bug-_parse_timestamps_in_record-throws-…
edgarrmondragon 20ca4b1
Merge branch 'main' into 1836-bug-_parse_timestamps_in_record-throws-…
edgarrmondragon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
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"}, | ||
}, | ||
}, | ||
["id"], | ||
) | ||
|
||
record_message = { | ||
"type": "RECORD", | ||
"stream": "users", | ||
"record": { | ||
"id": 1, | ||
"created_at": "2021-01-01T00:00:00+00:00", | ||
"missing_datetime": "2021-01-01T00:00:00+00:00", | ||
}, | ||
"time_extracted": "2021-01-01T00:00:00+00:00", | ||
"version": 100, | ||
} | ||
record = record_message["record"] | ||
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" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Using the
in
operator is a bit faster than try-except: