@@ -1080,7 +1080,9 @@ def remove_namespace(self, namespace_id: int) -> None:
10801080 # sneak in between the count and the delete below. No-op on
10811081 # SQLite (writes are already serialized at the database level).
10821082 self .db .execute (
1083- select (n .c .id ).where (n .c .id == namespace_id ).with_for_update ()
1083+ self ._namespaces_select (n .c .id )
1084+ .where (n .c .id == namespace_id )
1085+ .with_for_update ()
10841086 )
10851087 num_projects = self .count_projects (namespace_id )
10861088 if num_projects > 0 :
@@ -1216,7 +1218,9 @@ def remove_project(self, project_id: int) -> None:
12161218 # sneak in between the count and the delete below. No-op on
12171219 # SQLite (writes are already serialized at the database level).
12181220 self .db .execute (
1219- select (p .c .id ).where (p .c .id == project_id ).with_for_update ()
1221+ self ._projects_select (p .c .id )
1222+ .where (p .c .id == project_id )
1223+ .with_for_update ()
12201224 )
12211225 num_datasets = self .count_datasets (project_id )
12221226 if num_datasets > 0 :
@@ -1862,7 +1866,9 @@ def remove_dataset_version(
18621866 # if-empty below. No-op on SQLite (writes are already
18631867 # serialized at the database level).
18641868 self .db .execute (
1865- select (d .c .id ).where (d .c .id == dataset .id ).with_for_update ()
1869+ self ._datasets_select (d .c .id )
1870+ .where (d .c .id == dataset .id )
1871+ .with_for_update ()
18661872 )
18671873
18681874 self .db .execute (
@@ -1874,7 +1880,7 @@ def remove_dataset_version(
18741880 # Count from DB - in-memory dataset.versions may be incomplete.
18751881 remaining = next (
18761882 self .db .execute (
1877- select (f .count ())
1883+ self . _datasets_versions_select (f .count ())
18781884 .select_from (dv )
18791885 .where (dv .c .dataset_id == dataset .id )
18801886 )
@@ -2188,6 +2194,16 @@ def update_dataset_dependency_source(
21882194 q = q .values (** data )
21892195 self .db .execute (q )
21902196
2197+ @cached_property
2198+ def _dependency_datasets_source (self ):
2199+ # Source alias for direct-dependency queries; cached so the column hook
2200+ # and the FROM clause reference the same object. Override to filter.
2201+ return self ._datasets
2202+
2203+ @cached_property
2204+ def _dependency_namespaces_source (self ):
2205+ return self ._namespaces
2206+
21912207 @abstractmethod
21922208 def _dataset_dependencies_select_columns (self ) -> list ["SchemaItem" ]:
21932209 """
@@ -2211,9 +2227,9 @@ def get_direct_dataset_dependencies(
22112227 dataset : DatasetRecord ,
22122228 version : str ,
22132229 ) -> list [DatasetDependency | None ]:
2214- n = self ._namespaces
2230+ n = self ._dependency_namespaces_source
22152231 p = self ._projects
2216- d = self ._datasets
2232+ d = self ._dependency_datasets_source
22172233 dd = self ._datasets_dependencies
22182234 dv = self ._datasets_versions
22192235
@@ -2925,7 +2941,7 @@ def link_dataset_version_to_job(
29252941
29262942 # Also update dataset_version.job_id to point to this job
29272943 update_query = (
2928- self ._datasets_versions . update ()
2944+ self ._datasets_versions_update ()
29292945 .where (self ._datasets_versions .c .id == dataset_version_id )
29302946 .values (job_id = job_id )
29312947 )
0 commit comments