diff --git a/sdv/datasets/demo.py b/sdv/datasets/demo.py index 0589541f8..c6220af4f 100644 --- a/sdv/datasets/demo.py +++ b/sdv/datasets/demo.py @@ -224,6 +224,12 @@ def is_direct_json_under_prefix(key): raw = _get_data_from_bucket(key, bucket=bucket, client=client) metadict = json.loads(raw) if isinstance(metadict, dict) and metadict.get('METADATA_SPEC_VERSION') == version: + if version != 'V2': + warnings.warn( + 'An updated metadata V2 is not available for this dataset so the V1 ' + 'metadata was returned.\nYou should be able to model and sample with ' + 'the V1 metadata, but please report this issue to the DataCebo.' + ) return raw except Exception: diff --git a/tests/integration/datasets/test_demo.py b/tests/integration/datasets/test_demo.py index 8799bc298..d1c347367 100644 --- a/tests/integration/datasets/test_demo.py +++ b/tests/integration/datasets/test_demo.py @@ -137,6 +137,20 @@ def test_download_demo_adventure_works_raises_warning(preprocess_mock): download_demo(modality='multi_table', dataset_name='adventure-works') +def test_download_demo_raise_warning_v2_metadata(): + """Test that a warning is raised if the V2 metadata is not available.""" + # Setup + expected_warning = re.escape( + 'An updated metadata V2 is not available for this dataset so the V1 ' + 'metadata was returned.\nYou should be able to model and sample with' + ' the V1 metadata, but please report this issue to the DataCebo.' + ) + + # Run and Assert + with pytest.warns(UserWarning, match=expected_warning): + download_demo(modality='single_table', dataset_name='fake_hotel_guests') + + def test_save_resource(tmp_path): """Test saving an arbitary demo resource.""" # Setup diff --git a/tests/unit/datasets/test_demo.py b/tests/unit/datasets/test_demo.py index ab1c93c54..1fdcd68de 100644 --- a/tests/unit/datasets/test_demo.py +++ b/tests/unit/datasets/test_demo.py @@ -417,6 +417,11 @@ def test__get_first_v2_metadata_bytes_falls_back_to_v1(mock_get): v2 = json.dumps({'METADATA_SPEC_VERSION': 'V1'}).encode() bad = b'not-json' v1 = json.dumps({'METADATA_SPEC_VERSION': 'V1'}).encode() + expected_warning = re.escape( + 'An updated metadata V2 is not available for this dataset so the V1 ' + 'metadata was returned.\nYou should be able to model and sample with' + ' the V1 metadata, but please report this issue to the DataCebo.' + ) def side_effect(key, bucket, client): return { @@ -433,9 +438,10 @@ def side_effect(key, bucket, client): ] # Run - got = _get_first_v2_metadata_bytes( - contents, 'single_table/dataset/', bucket='test_bucket', client=None - ) + with pytest.warns(UserWarning, match=expected_warning): + got = _get_first_v2_metadata_bytes( + contents, 'single_table/dataset/', bucket='test_bucket', client=None + ) # Assert assert got == v1