Feat: Add Safe Data Preview#36
Conversation
69ef38f to
9111d65
Compare
cph-datamasque
left a comment
There was a problem hiding this comment.
Have a think about whether the UnknownPreview is a safe idea from the point of view of a person using this library.
Remove tests that are just testing pydantic, and collapse repetitive tests using pytest.mark.parametrize().
| pass | ||
| try: | ||
| return UnknownPreview.model_validate(value) | ||
| except ValidationError: |
There was a problem hiding this comment.
This kind of future-proofing fallback isn't present for any other model in the client, so unsure how I feel about it - catching client bugs is good and having a defined shape makes using it much easier. But on the other hand we can catch bugs using tests. What do you think?
There was a problem hiding this comment.
Yeah I agree with the principle in general but would defend it here.
I added this fallback so in some case where something changed in datamasque, say a new kind was added, and dm-python wasn't updated then falling back wouldn't cause the discovery run to crash.
In my opinion this is important so a change in SDP doesn't crash discovery runs since there's nothing pinning the client and servers together currently.
However happy to change it if I'm wrong.
There was a problem hiding this comment.
After looking into it further have concluded that it's not as bad as I thought if a run fails here since discovery runs are owned inside DM itself. Therefore, will get rid of the UnknownPreview entirely since the shape should be always known.
Would be good, in the future, to add some sort of compatibility check/matrix between DM and dm-python.
| } | ||
|
|
||
|
|
||
| def test_schema_discovery_request_model_dump_includes_safe_data_preview(): |
There was a problem hiding this comment.
First of several tests that don't add any value. This is just testing pydantic's behaviour. If you want to test this, at least call the API method that sends the SD request and check the request body (or fold into one of the existing tests that does that).
| assert preview.statistics_common.count_distinct == 988 | ||
|
|
||
|
|
||
| def test_schema_discovery_result_without_safe_data_preview(): |
There was a problem hiding this comment.
Borderline not worth it (again you're testing that the default is None, which it is because we can see it right there - no actual logic tested, except for the bit where the validator tolerates and spits out None when given None).
There was a problem hiding this comment.
Removed. Good spotting!
| _assert_no_unexpected_extras(item) | ||
|
|
||
|
|
||
| def test_each_preview_parses_to_its_typed_variant(): |
There was a problem hiding this comment.
use pytest.mark.parametrize()
| assert type(parse_safe_data_preview(_UNSUPPORTED_PREVIEW)) is UnsupportedPreview | ||
|
|
||
|
|
||
| def test_each_preview_round_trips(): |
There was a problem hiding this comment.
tests pydantic not our code, remove
| assert parse_safe_data_preview(_UNSUPPORTED_PREVIEW).model_dump(mode="json") == _UNSUPPORTED_PREVIEW | ||
|
|
||
|
|
||
| def test_each_preview_has_no_untyped_fields(): |
There was a problem hiding this comment.
use pytest.mark.parametrize
| assert preview.statistics_kind.reason == "Binary data isn't previewed" | ||
|
|
||
|
|
||
| def test_none_passes_through(): |
There was a problem hiding this comment.
already tested by the one I flagged earlier, remove one of them
There was a problem hiding this comment.
Combined all tests testing null behaviour into one with pytest.mark.parametrize. Also removed one since it was testing the same arm.
| assert preview.statistics_common.count_null == 0 | ||
|
|
||
|
|
||
| def test_unparseable_payload_falls_back_without_raising(): |
There was a problem hiding this comment.
this is the kind of thing I was worried about with the fallback. If someone wrote some code using the library that tried to do maths on the count_row, it would just crash. We should at least ensure UnknownPreview has all fields present, typed, and with defaults if we are going to keep it
| assert preview.kind == 123 | ||
|
|
||
|
|
||
| def test_non_dict_preview_is_none(): |
There was a problem hiding this comment.
shouldn't this be an error?
| * ``safe_data_preview`` on ``InDataDiscoveryConfig`` (via ``SafeDataPreviewOptions``) | ||
| to configure or disable the preview. | ||
| * ``safe_data_preview`` on schema-discovery result columns and file-discovery locators, | ||
| typed by ``kind``. |
There was a problem hiding this comment.
line length is 120
| * ``safe_data_preview`` on ``InDataDiscoveryConfig`` (via ``SafeDataPreviewOptions``) | |
| to configure or disable the preview. | |
| * ``safe_data_preview`` on schema-discovery result columns and file-discovery locators, | |
| typed by ``kind``. | |
| * ``safe_data_preview`` on ``InDataDiscoveryConfig`` (via ``SafeDataPreviewOptions``) to configure or disable the preview. | |
| * ``safe_data_preview`` on schema-discovery result columns and file-discovery locators, typed by ``kind``. |
62e576e to
5bcf818
Compare
799f58f to
10f2e69
Compare
10f2e69 to
f01e0b2
Compare
kanewilliams
left a comment
There was a problem hiding this comment.
Looks good on my end, conditional on @cph-datamasque's review
Adds
SafeDataPreviewOptionsonInDataDiscoveryConfigand a typedsafe_data_previewfield on schema-discovery result columns. Changelog entry under 1.1.8 (unreleased).