@@ -84,15 +84,19 @@ def validate_table_exists(
84
84
85
85
@staticmethod
86
86
def validate_uniqueness (
87
- database_id : int ,
87
+ database : Database ,
88
88
table : Table ,
89
89
dataset_id : int | None = None ,
90
90
) -> bool :
91
+ # The catalog might not be set even if the database supports catalogs, in case
92
+ # multi-catalog is disabled.
93
+ catalog = table .catalog or database .get_default_catalog ()
94
+
91
95
dataset_query = db .session .query (SqlaTable ).filter (
92
96
SqlaTable .table_name == table .table ,
93
97
SqlaTable .schema == table .schema ,
94
- SqlaTable .catalog == table . catalog ,
95
- SqlaTable .database_id == database_id ,
98
+ SqlaTable .catalog == catalog ,
99
+ SqlaTable .database_id == database . id ,
96
100
)
97
101
98
102
if dataset_id :
@@ -103,15 +107,19 @@ def validate_uniqueness(
103
107
104
108
@staticmethod
105
109
def validate_update_uniqueness (
106
- database_id : int ,
110
+ database : Database ,
107
111
table : Table ,
108
112
dataset_id : int ,
109
113
) -> bool :
114
+ # The catalog might not be set even if the database supports catalogs, in case
115
+ # multi-catalog is disabled.
116
+ catalog = table .catalog or database .get_default_catalog ()
117
+
110
118
dataset_query = db .session .query (SqlaTable ).filter (
111
119
SqlaTable .table_name == table .table ,
112
- SqlaTable .database_id == database_id ,
120
+ SqlaTable .database_id == database . id ,
113
121
SqlaTable .schema == table .schema ,
114
- SqlaTable .catalog == table . catalog ,
122
+ SqlaTable .catalog == catalog ,
115
123
SqlaTable .id != dataset_id ,
116
124
)
117
125
return not db .session .query (dataset_query .exists ()).scalar ()
0 commit comments