Skip to content

Commit 5f26a17

Browse files
committed
Warn about ignoring unsupported constraints
1 parent f7d4d73 commit 5f26a17

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

tests/unit/sqlalchemy/test_compiler.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from sqlalchemy import select
2020
from sqlalchemy import String
2121
from sqlalchemy import Table
22+
from sqlalchemy.exc import SAWarning
2223
from sqlalchemy.schema import CreateTable
2324
from sqlalchemy.sql import column
2425
from sqlalchemy.sql import table
@@ -194,18 +195,21 @@ def test_try_cast(dialect):
194195

195196

196197
def test_catalogs_create_table_with_pk(dialect):
197-
statement = CreateTable(table_with_pk)
198-
query = statement.compile(dialect=dialect)
199-
assert 'primary key' not in str(query).lower()
198+
with pytest.warns(SAWarning, match="Trino does not support PRIMARY KEY constraints. Constraint will be ignored."):
199+
statement = CreateTable(table_with_pk)
200+
query = statement.compile(dialect=dialect)
201+
assert 'primary key' not in str(query).lower()
200202

201203

202204
def test_catalogs_create_table_with_fk(dialect):
203-
statement = CreateTable(table_with_fk)
204-
query = statement.compile(dialect=dialect)
205-
assert 'foreign key' not in str(query).lower()
205+
with pytest.warns(SAWarning, match="Trino does not support FOREIGN KEY constraints. Constraint will be ignored."):
206+
statement = CreateTable(table_with_fk)
207+
query = statement.compile(dialect=dialect)
208+
assert 'foreign key' not in str(query).lower()
206209

207210

208211
def test_catalogs_create_table_with_unique(dialect):
209-
statement = CreateTable(table_with_unique)
210-
query = statement.compile(dialect=dialect)
211-
assert 'unique' not in str(query).lower()
212+
with pytest.warns(SAWarning, match="Trino does not support UNIQUE constraints. Constraint will be ignored."):
213+
statement = CreateTable(table_with_unique)
214+
query = statement.compile(dialect=dialect)
215+
assert 'unique' not in str(query).lower()

trino/sqlalchemy/compiler.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from sqlalchemy.sql import sqltypes
1515
from sqlalchemy.sql.base import DialectKWArgs
1616
from sqlalchemy.sql.functions import GenericFunction
17+
from sqlalchemy.util import warn as SAWarn
1718

1819
# https://trino.io/docs/current/language/reserved.html
1920
RESERVED_WORDS = {
@@ -182,12 +183,15 @@ def visit_try_cast(self, element, **kw):
182183

183184
class TrinoDDLCompiler(compiler.DDLCompiler):
184185
def visit_foreign_key_constraint(self, constraint, **kw):
186+
SAWarn("Trino does not support FOREIGN KEY constraints. Constraint will be ignored.")
185187
return None
186188

187189
def visit_primary_key_constraint(self, constraint, **kw):
190+
SAWarn("Trino does not support PRIMARY KEY constraints. Constraint will be ignored.")
188191
return None
189192

190193
def visit_unique_constraint(self, constraint, **kw):
194+
SAWarn("Trino does not support UNIQUE constraints. Constraint will be ignored.")
191195
return None
192196

193197

0 commit comments

Comments
 (0)