Skip to content

Commit 4782ba3

Browse files
authored
fix: Keep HybridOnlineStore routing_tag across FeatureViews (#6769)
* fix: keep HybridOnlineStore routing_tag across FeatureViews HybridOnlineStore.update() applied the first FeatureView and then failed on the second with ValueError: FeatureView must have a 'tribe' tag to use HybridOnlineStore no matter how the views were tagged. The message reports 'tribe' — the fallback, not the configured routing_tag — because config.online_store is no longer the HybridOnlineStoreConfig by the time the second view is read. Two causes: 1. _prepare_repo_conf mutated the caller's RepoConfig. `rconfig = config` is an alias, so both the attribute assignment and the __dict__ writes landed on the caller's object and replaced online_store with the selected backend's config. It also injected `type` into online_store.conf, which belongs to the user's config. 2. update() and teardown() rebound the `config` parameter inside their loops, so the next iteration read routing_tag off the narrowed config even once the mutation was gone. Build the returned mapping from a copy, construct a new dict for the backend conf, and assign the per-backend RepoConfig to a local name in the loops. Behaviour is otherwise unchanged: the returned kwargs are identical to what the mutating version produced. Adds a unit regression test covering both the multi-FeatureView routing and the caller's config staying intact. Both fail on master. Signed-off-by: Jade <retrorca@gmail.com> * fix: route only each backend's own FeatureViews in HybridOnlineStore Backends act on every FeatureView handed to them, so passing the full keep/delete lists made e.g. SQLite create tables for Redis-routed views, and teardown let each backend drop another backend's tables. - group FeatureViews by routing tag once, call each backend with only its own subset - update() now also reaches a backend that has deletions but no kept views; previously it was never called and its tables were never dropped - teardown() drops the (tribe, type, id(conf)) dedup set: grouping already gives one call per backend, and the old dedup skipped the second view routed to the same backend Signed-off-by: Jade <retrorca@gmail.com> * test: annotate HybridOnlineStore test signatures Per review feedback on the fixtures and test functions. The whole file is covered rather than only the flagged lines, so the signatures stay consistent. No behaviour change; `ruff check` and `ruff format --check` pass on sdk/python/feast and sdk/python/tests. Signed-off-by: Jade <retrorca@gmail.com> * test: cover the untagged and unrouted paths in HybridOnlineStore Codecov flagged the new _group_by_routing_tag branches as the only uncovered lines in the patch: nothing exercised an untagged FeatureView or a tag value with no configured backend. - update() raises naming the *configured* routing tag, not the "tribe" default, when a kept view is untagged — that wrong name was the symptom this PR set out to fix - update() skips an untagged view in tables_to_delete instead of raising - update() raises NotImplementedError for a tag no backend claims - teardown() skips such a tag rather than failing _feature_view() takes Optional[str] so a view can be built without the tag. No production change; 9 tests pass, patch coverage is now complete (branch partials on the changed lines go to zero). Signed-off-by: Jade <retrorca@gmail.com> --------- Signed-off-by: Jade <retrorca@gmail.com>
1 parent a037863 commit 4782ba3

2 files changed

Lines changed: 361 additions & 45 deletions

File tree

‎sdk/python/feast/infra/online_stores/hybrid_online_store/hybrid_online_store.py‎

Lines changed: 79 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -139,27 +139,69 @@ def _prepare_repo_conf(self, config: RepoConfig, online_store_type: str):
139139
"""
140140
Prepare a RepoConfig for the selected online store backend.
141141
142+
The caller's RepoConfig is left untouched: the returned mapping is built
143+
from a copy. Mutating it in place replaced the caller's HybridOnlineStore
144+
config with the selected backend's config, so every later lookup of
145+
``routing_tag`` fell back to the "tribe" default.
146+
142147
Args:
143148
config: The original Feast RepoConfig.
144149
online_store_type: The type of the online store backend to use.
145150
Returns:
146151
A dictionary representing the updated RepoConfig for the selected backend.
147152
"""
148-
rconfig = config
153+
online_config = config.online_config
149154
for online_store in config.online_store.online_stores:
150155
if online_store.type.split(".")[-1].lower() == online_store_type.lower():
151-
rconfig.online_config = online_store.conf
152-
rconfig.online_config["type"] = online_store.type
153-
data = rconfig.__dict__
156+
# New dict rather than a mutated one: ``conf`` belongs to the
157+
# caller's config and is read again on the next lookup.
158+
online_config = {**online_store.conf, "type": online_store.type}
159+
data = dict(config.__dict__)
154160
data["registry"] = data["registry_config"]
155161
data["offline_store"] = data["offline_config"]
156-
data["online_store"] = data["online_config"]
162+
data["online_config"] = online_config
163+
data["online_store"] = online_config
157164
return data
158165

159166
def _get_routing_tag_value(self, table: FeatureView, config: RepoConfig):
160167
tag_name = getattr(config.online_store, "routing_tag", "tribe")
161168
return table.tags.get(tag_name)
162169

170+
def _group_by_routing_tag(
171+
self,
172+
tables: Sequence[FeatureView],
173+
config: RepoConfig,
174+
require_tag: bool,
175+
) -> Dict[str, List[FeatureView]]:
176+
"""
177+
Bucket FeatureViews by the (lower-cased) value of their routing tag.
178+
179+
Backends act on every FeatureView handed to them, so each one must only
180+
ever see its own bucket. Passing the full list made e.g. SQLite create
181+
tables for Redis-routed views.
182+
183+
Args:
184+
tables: FeatureViews to group.
185+
config: Feast RepoConfig.
186+
require_tag: Raise on an untagged FeatureView instead of skipping it.
187+
Returns:
188+
Mapping of tag value to the FeatureViews carrying it.
189+
Raises:
190+
ValueError: If ``require_tag`` and a FeatureView has no routing tag.
191+
"""
192+
grouped: Dict[str, List[FeatureView]] = {}
193+
for table in tables:
194+
tribe = self._get_routing_tag_value(table, config)
195+
if not tribe:
196+
if require_tag:
197+
tag_name = getattr(config.online_store, "routing_tag", "tribe")
198+
raise ValueError(
199+
f"FeatureView must have a '{tag_name}' tag to use HybridOnlineStore."
200+
)
201+
continue
202+
grouped.setdefault(tribe.lower(), []).append(table)
203+
return grouped
204+
163205
def online_write_batch(
164206
self,
165207
config: RepoConfig,
@@ -266,28 +308,32 @@ def update(
266308
ValueError: If a FeatureView does not have the required tag.
267309
NotImplementedError: If no online store is found for a tag value.
268310
"""
269-
for table in tables_to_keep:
270-
tribe = self._get_routing_tag_value(table, config)
271-
if not tribe:
272-
tag_name = getattr(config.online_store, "routing_tag", "tribe")
273-
raise ValueError(
274-
f"FeatureView must have a '{tag_name}' tag to use HybridOnlineStore."
275-
)
311+
keep_by_tribe = self._group_by_routing_tag(
312+
tables_to_keep, config, require_tag=True
313+
)
314+
# Untagged views on the way out are skipped rather than fatal: they may
315+
# predate the routing tag, and there is no backend to route them to.
316+
delete_by_tribe = self._group_by_routing_tag(
317+
tables_to_delete, config, require_tag=False
318+
)
319+
for tribe in {**keep_by_tribe, **delete_by_tribe}:
276320
online_store = self._get_online_store(tribe, config)
277-
if online_store:
278-
config = RepoConfig(**self._prepare_repo_conf(config, tribe))
279-
online_store.update(
280-
config,
281-
tables_to_delete,
282-
tables_to_keep,
283-
entities_to_delete,
284-
entities_to_keep,
285-
partial,
286-
)
287-
else:
321+
if not online_store:
288322
raise NotImplementedError(
289323
f"No online store found for {getattr(config.online_store, 'routing_tag', 'tribe')} tag '{tribe}'. Please check your configuration."
290324
)
325+
# Local name: rebinding `config` here would feed the next iteration
326+
# the selected backend's config instead of the hybrid one, losing
327+
# `routing_tag`.
328+
store_config = RepoConfig(**self._prepare_repo_conf(config, tribe))
329+
online_store.update(
330+
store_config,
331+
delete_by_tribe.get(tribe, []),
332+
keep_by_tribe.get(tribe, []),
333+
entities_to_delete,
334+
entities_to_keep,
335+
partial,
336+
)
291337

292338
def teardown(
293339
self,
@@ -303,25 +349,13 @@ def teardown(
303349
tables: Sequence of FeatureViews to teardown.
304350
entities: Sequence of Entities to teardown.
305351
"""
306-
# Use a set of (tribe, store_type, conf_id) to avoid duplicate teardowns for the same instance
307-
tribes_seen = set()
308-
online_stores_cfg = getattr(config.online_store, "online_stores", [])
309-
tag_name = getattr(config.online_store, "routing_tag", "tribe")
310-
for table in tables:
311-
tribe = table.tags.get(tag_name)
312-
if not tribe:
313-
continue
314-
# Find all store configs matching this tribe (supporting multiple instances of the same type)
315-
for store_cfg in online_stores_cfg:
316-
store_type = store_cfg.type
317-
# Use id(store_cfg.conf) to distinguish different configs of the same type
318-
key = (tribe, store_type, id(store_cfg.conf))
319-
if key in tribes_seen:
320-
continue
321-
tribes_seen.add(key)
322-
# Only select the online store if tribe matches the type (or you can add a mapping in config for more flexibility)
323-
if tribe.lower() == store_type.split(".")[-1].lower():
324-
online_store = self._get_online_store(tribe, config)
325-
if online_store:
326-
config = RepoConfig(**self._prepare_repo_conf(config, tribe))
327-
online_store.teardown(config, tables, entities)
352+
# Grouping both dedupes backends and keeps each one from tearing down
353+
# another backend's FeatureViews. Untagged views have no backend to
354+
# route to and are skipped, as before.
355+
for tribe, tribe_tables in self._group_by_routing_tag(
356+
tables, config, require_tag=False
357+
).items():
358+
online_store = self._get_online_store(tribe, config)
359+
if online_store:
360+
store_config = RepoConfig(**self._prepare_repo_conf(config, tribe))
361+
online_store.teardown(store_config, tribe_tables, entities)

0 commit comments

Comments
 (0)