Skip to content

Commit 51cdc53

Browse files
authored
fix: don't introspect internal UNIQUE constraints (#244)
1 parent c3b5907 commit 51cdc53

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

create_test_database.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def create_test_instance():
7070
configs = list(CLIENT.list_instance_configs())
7171
if not USE_EMULATOR:
7272
# Filter out non "us" locations
73-
configs = [config for config in configs if "-us-" in config.name]
73+
configs = [config for config in configs if "europe-north1" in config.name]
7474

7575
instance_config = configs[0].name
7676
create_time = str(int(time.time()))

google/cloud/sqlalchemy_spanner/sqlalchemy_spanner.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,12 @@ def get_unique_constraints(self, connection, table_name, schema=None, **kw):
873873
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS tc
874874
JOIN INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE AS ccu
875875
ON ccu.CONSTRAINT_NAME = tc.CONSTRAINT_NAME
876-
WHERE tc.TABLE_NAME="{table_name}" AND tc.CONSTRAINT_TYPE = "UNIQUE"
876+
LEFT JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS AS rc
877+
on tc.CONSTRAINT_NAME = rc.CONSTRAINT_NAME
878+
WHERE
879+
tc.TABLE_NAME="{table_name}"
880+
AND tc.CONSTRAINT_TYPE = "UNIQUE"
881+
AND rc.CONSTRAINT_NAME IS NOT NULL
877882
""".format(
878883
table_name=table_name
879884
)

0 commit comments

Comments
 (0)