Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions sdk/python/feast/infra/passthrough_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,14 +511,23 @@ def retrieve_saved_dataset(
# ToDo: replace hardcoded value
event_ts_column = "event_timestamp"

# A dataset registered from existing storage has no event range, so
# leave a missing bound open instead of filtering on it.
start_date = None
if dataset.min_event_timestamp is not None:
start_date = make_tzaware(dataset.min_event_timestamp)
end_date = None
if dataset.max_event_timestamp is not None:
end_date = make_tzaware(dataset.max_event_timestamp + timedelta(seconds=1))

return self.offline_store.pull_all_from_table_or_query(
config=config,
data_source=dataset.storage.to_data_source(),
join_key_columns=dataset.join_keys,
feature_name_columns=feature_name_columns,
timestamp_field=event_ts_column,
start_date=make_tzaware(dataset.min_event_timestamp), # type: ignore
end_date=make_tzaware(dataset.max_event_timestamp + timedelta(seconds=1)), # type: ignore
start_date=start_date,
end_date=end_date,
)

def write_feature_service_logs(
Expand Down
24 changes: 17 additions & 7 deletions sdk/python/feast/infra/registry/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -1294,15 +1294,25 @@ def apply_saved_dataset(
existing_saved_dataset_proto.spec.name == saved_dataset_proto.spec.name
and existing_saved_dataset_proto.spec.project == project
):
existing_meta = existing_saved_dataset_proto.meta
saved_dataset.created_timestamp = (
existing_saved_dataset_proto.meta.created_timestamp.ToDatetime()
)
saved_dataset.min_event_timestamp = (
existing_saved_dataset_proto.meta.min_event_timestamp.ToDatetime()
)
saved_dataset.max_event_timestamp = (
existing_saved_dataset_proto.meta.max_event_timestamp.ToDatetime()
existing_meta.created_timestamp.ToDatetime()
)
# Reading the dataset filters on this range, so only keep the
# stored one if the new dataset does not have its own. It does
# when its data was overwritten.
if saved_dataset.min_event_timestamp is None and existing_meta.HasField(
"min_event_timestamp"
):
saved_dataset.min_event_timestamp = (
existing_meta.min_event_timestamp.ToDatetime()
)
if saved_dataset.max_event_timestamp is None and existing_meta.HasField(
"max_event_timestamp"
):
saved_dataset.max_event_timestamp = (
existing_meta.max_event_timestamp.ToDatetime()
)
Comment on lines +1304 to +1315

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Dataset preview errors after metadata edits

When a user edits a registered dataset with no event bounds, apply_saved_dataset leaves both bounds unset. The saved dataset reader requires both, so the preview returns HTTP 500 instead of an empty result.

Learn more

Register Dataset registers existing storage without supplying event timestamps, and Edit Dataset sends the same registration request with overwrite enabled. Before this change, editing a registration with no bounds replaced them with epoch timestamps, so the file offline store could execute the preview query, albeit with the wrong range. The new behavior keeps the bounds absent, but retrieve_saved_dataset still converts the lower bound and adds a second to the upper bound unconditionally. The preview endpoint turns the resulting exception into HTTP 500.

Example: Register a Parquet file containing January 2026 rows, then edit only the dataset description and open the sample tab. Before this change, the sample request succeeded with zero rows because it filtered near the epoch. It now fails before querying the file.

Recommended fix: Keep absent bounds absent in the registry. Make PassthroughProvider.retrieve_saved_dataset handle missing bounds explicitly, translating them to unbounded reads where supported. The Dask file store already skips the corresponding filters. Add a regression test for previewing an edited registration without event bounds.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 457ac39. PassthroughProvider.retrieve_saved_dataset now passes a missing min_event_timestamp or max_event_timestamp to pull_all_from_table_or_query as None instead of converting it, so a dataset without an event range is read unbounded on that side. The bounds that are set are handled as before (tz-aware, one second added to the upper one).

Tests added: test_saved_dataset_preview_without_event_range_via_rest registers a Parquet file over REST, edits it with allow_override, checks no range is stored, and reads GET /saved_datasets/data/{name} (3 rows; returned 500 before the change). test_retrieve_saved_dataset_leaves_missing_event_bounds_open in tests/unit/infra/test_provider.py covers no bounds, either bound, and both.

saved_dataset_proto = saved_dataset.to_proto()
saved_dataset_proto.spec.project = project
del self.cached_registry_proto.saved_datasets[idx]
Expand Down
2 changes: 2 additions & 0 deletions sdk/python/feast/saved_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ def to_proto(self) -> SavedDatasetProto:
meta = SavedDatasetMeta()
if self.created_timestamp:
meta.created_timestamp.FromDatetime(self.created_timestamp)
if self.last_updated_timestamp:
meta.last_updated_timestamp.FromDatetime(self.last_updated_timestamp)
if self.min_event_timestamp:
meta.min_event_timestamp.FromDatetime(self.min_event_timestamp)
if self.max_event_timestamp:
Expand Down
38 changes: 38 additions & 0 deletions sdk/python/tests/unit/api/test_api_rest_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,44 @@ def test_saved_datasets_via_rest(fastapi_test_app):
assert data["error_type"] == "RequestValidationError"


def test_saved_dataset_preview_without_event_range_via_rest(fastapi_test_app):
response = fastapi_test_app.get(
"/saved_datasets/test_saved_dataset?project=demo_project"
)
storage_path = response.json()["spec"]["storage"]["fileStorage"]["uri"]

# Registering existing storage stores no event range, and editing the
# dataset registers it again with allow_override.
payload = {
"name": "registered_dataset",
"project": "demo_project",
"features": ["user_profile:age", "user_profile:income"],
"join_keys": ["user_id"],
"storage_path": storage_path,
}
response = fastapi_test_app.post("/saved_datasets", json=payload)
assert response.status_code == 200
payload.update(description="Edited description", allow_override=True)
response = fastapi_test_app.post("/saved_datasets", json=payload)
assert response.status_code == 200

response = fastapi_test_app.get(
"/saved_datasets/registered_dataset?project=demo_project"
)
assert response.status_code == 200
meta = response.json()["meta"]
assert "minEventTimestamp" not in meta
assert "maxEventTimestamp" not in meta

response = fastapi_test_app.get(
"/saved_datasets/data/registered_dataset?project=demo_project"
)
assert response.status_code == 200
data = response.json()
assert data["total_rows"] == 3
assert sorted(row["user_id"] for row in data["rows"]) == [1, 2, 3]


@pytest.fixture
def fastapi_test_app_with_multiple_objects():
"""Test app with multiple objects for pagination and sorting tests."""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
"""Unit tests for the timestamps of a SavedDataset that is re-applied."""

from datetime import datetime, timezone

import pytest

from feast.infra.offline_stores.file_source import SavedDatasetFileStorage
from feast.infra.registry.registry import Registry
from feast.repo_config import RegistryConfig
from feast.saved_dataset import SavedDataset

PROJECT = "test_project"


def _day(day):
return datetime(2026, 1, day)


def _saved_dataset(min_event_timestamp=None, max_event_timestamp=None):
dataset = SavedDataset(
name="ds",
features=["fv:f1"],
join_keys=["e_id"],
storage=SavedDatasetFileStorage(path="ds.parquet"),
)
dataset.min_event_timestamp = min_event_timestamp
dataset.max_event_timestamp = max_event_timestamp
return dataset


@pytest.fixture
def registry(tmp_path):
config = RegistryConfig(path=str(tmp_path / "registry.db"), cache_ttl_seconds=0)
return Registry(PROJECT, config, None)


@pytest.mark.parametrize("tzinfo", [None, timezone.utc])
def test_reapplied_saved_dataset_stores_its_new_event_range(registry, tzinfo):
registry.apply_saved_dataset(_saved_dataset(_day(1), _day(3)), PROJECT)
registry.apply_saved_dataset(
_saved_dataset(
_day(11).replace(tzinfo=tzinfo), _day(13).replace(tzinfo=tzinfo)
),
PROJECT,
)

stored = registry.get_saved_dataset("ds", PROJECT)
assert stored.min_event_timestamp == _day(11)
assert stored.max_event_timestamp == _day(13)


def test_reapplied_saved_dataset_without_event_range_keeps_the_stored_one(registry):
registry.apply_saved_dataset(_saved_dataset(_day(1), _day(3)), PROJECT)
registry.apply_saved_dataset(_saved_dataset(), PROJECT)

stored = registry.get_saved_dataset("ds", PROJECT)
assert stored.min_event_timestamp == _day(1)
assert stored.max_event_timestamp == _day(3)


def test_reapplied_saved_dataset_does_not_invent_an_event_range(registry):
registry.apply_saved_dataset(_saved_dataset(), PROJECT)
registry.apply_saved_dataset(_saved_dataset(), PROJECT)

stored = registry.get_saved_dataset("ds", PROJECT)
assert stored.min_event_timestamp is None
assert stored.max_event_timestamp is None


def test_saved_dataset_stores_last_updated_timestamp(registry):
registry.apply_saved_dataset(_saved_dataset(_day(1), _day(3)), PROJECT)
first = registry.get_saved_dataset("ds", PROJECT)
assert first.last_updated_timestamp is not None

registry.apply_saved_dataset(_saved_dataset(_day(1), _day(3)), PROJECT)
second = registry.get_saved_dataset("ds", PROJECT)
assert second.created_timestamp == first.created_timestamp
assert second.last_updated_timestamp >= first.last_updated_timestamp
53 changes: 52 additions & 1 deletion sdk/python/tests/unit/infra/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,18 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from datetime import timedelta
from datetime import datetime, timedelta, timezone
from unittest.mock import Mock

import pytest

from feast import BigQuerySource
from feast.entity import Entity
from feast.feature_view import FeatureView
from feast.field import Field
from feast.infra.offline_stores.file_source import SavedDatasetFileStorage
from feast.infra.passthrough_provider import PassthroughProvider
from feast.saved_dataset import SavedDataset
from feast.types import String
from feast.utils import _get_column_names

Expand Down Expand Up @@ -45,3 +51,48 @@ def test_get_column_names_preserves_feature_ordering():

_, feature_list, _, _ = _get_column_names(fv, [entity])
assert feature_list == ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]


@pytest.mark.parametrize(
"min_event_timestamp, max_event_timestamp, expected_start, expected_end",
[
(None, None, None, None),
(
datetime(2026, 1, 1),
None,
datetime(2026, 1, 1, tzinfo=timezone.utc),
None,
),
(
None,
datetime(2026, 1, 3),
None,
datetime(2026, 1, 3, 0, 0, 1, tzinfo=timezone.utc),
),
(
datetime(2026, 1, 1),
datetime(2026, 1, 3),
datetime(2026, 1, 1, tzinfo=timezone.utc),
datetime(2026, 1, 3, 0, 0, 1, tzinfo=timezone.utc),
),
],
)
def test_retrieve_saved_dataset_leaves_missing_event_bounds_open(
min_event_timestamp, max_event_timestamp, expected_start, expected_end
):
dataset = SavedDataset(
name="ds",
features=["fv:f1"],
join_keys=["e_id"],
storage=SavedDatasetFileStorage(path="ds.parquet"),
)
dataset.min_event_timestamp = min_event_timestamp
dataset.max_event_timestamp = max_event_timestamp
provider = PassthroughProvider(Mock())
provider._offline_store = Mock()

provider.retrieve_saved_dataset(config=Mock(), dataset=dataset)

pull_kwargs = provider._offline_store.pull_all_from_table_or_query.call_args.kwargs
assert pull_kwargs["start_date"] == expected_start
assert pull_kwargs["end_date"] == expected_end
Loading