⚡ Sangsakala Proxy 🏠 Home
Skip to content
Merged
Prev Previous commit
Next Next commit
fix: use regex for precise version table matching in teardown
LIKE _v% could match unrelated tables (e.g. driver_verbose when
dropping versions for driver). Switch to REGEXP/~ with _v[0-9]+$
pattern. Also scope Postgres pg_tables query by schemaname.

Signed-off-by: yassinnouh21 <yassinnouh21@gmail.com>
  • Loading branch information
YassinNouh21 authored and ntkathole committed Apr 6, 2026
commit d827045fa0259f4f7fcaca697dc96c1805e60e7e
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,8 @@ def _drop_all_version_tables(cur: Cursor, project: str, table: FeatureView) -> N
base = f"{project}_{table.name}"
cur.execute(
"SELECT table_name FROM information_schema.tables "
"WHERE table_schema = DATABASE() AND (table_name = %s OR table_name LIKE %s)",
(base, f"{base}_v%"),
"WHERE table_schema = DATABASE() AND (table_name = %s OR table_name REGEXP %s)",
(base, f"^{base}_v[0-9]+$"),
)
for (name,) in cur.fetchall():
cur.execute(f"DROP INDEX IF EXISTS {name}_ek ON {name};")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ def update(
versioning = config.registry.enable_online_feature_view_versioning
for table in tables_to_delete:
if versioning:
_drop_all_version_tables(cur, project, table)
_drop_all_version_tables(cur, project, table, schema_name)
else:
table_name = _table_id(project, table)
cur.execute(_drop_table_and_index(table_name))
Expand Down Expand Up @@ -387,12 +387,13 @@ def teardown(
entities: Sequence[Entity],
):
project = config.project
schema_name = config.online_store.db_schema or config.online_store.user
versioning = config.registry.enable_online_feature_view_versioning
try:
with self._get_conn(config) as conn, conn.cursor() as cur:
for table in tables:
if versioning:
_drop_all_version_tables(cur, project, table)
_drop_all_version_tables(cur, project, table, schema_name)
else:
table_name = _table_id(project, table)
cur.execute(_drop_table_and_index(table_name))
Expand Down Expand Up @@ -844,14 +845,19 @@ def _drop_table_and_index(table_name):
)


def _drop_all_version_tables(cur, project: str, table: FeatureView) -> None:
def _drop_all_version_tables(cur, project: str, table: FeatureView, schema_name: Optional[str] = None) -> None:
"""Drop the base table and all versioned tables (e.g. _v1, _v2, ...)."""
base = f"{project}_{table.name}"
cur.execute(
sql.SQL(
"SELECT tablename FROM pg_tables WHERE tablename = %s OR tablename LIKE %s"
),
(base, f"{base}_v%"),
)
if schema_name:
cur.execute(
"SELECT tablename FROM pg_tables "
"WHERE schemaname = %s AND (tablename = %s OR tablename ~ %s)",
(schema_name, base, f"^{base}_v[0-9]+$"),
)
else:
cur.execute(
"SELECT tablename FROM pg_tables WHERE tablename = %s OR tablename ~ %s",
(base, f"^{base}_v[0-9]+$"),
)
for (name,) in cur.fetchall():
cur.execute(_drop_table_and_index(name))