Hi, we noticed that the copying of ExcludeConstraints as part of a tometadata invocation fails for constraints with column-based expressions. The copy implementation of ExcludeConstraint passes the strname's of its columns to the construction of the new constraint, which is fine for regular columns, but not for more complex expressions. We've added a small test case (in test_metadata) that reproduces the failure below. We also implemented a temporary solution that seems to fix the issue by passing copies of the constraint's column expressions instead. We are on version 1.3.18.
Temporary solution: ```python #elements = [(_copy_expression(col_expr, self.table, kw['target_table']), self.operators[col]) for col, col_expr in zip(self.columns.keys(), self.columns.values())] elements = [(col, self.operators[col]) for col in self.columns.keys()] ``` Test case ```python from sqlalchemy.dialects.postgresql import ExcludeConstraint from sqlalchemy import column, Date, literal_column class ToMetaDataExcludeConstraint(fixtures.TestBase, ComparesTables): @testing.requires.check_constraints def test_copy(self): from sqlalchemy.testing.schema import Table meta = MetaData() table = Table( "mytable", meta, Column("myid", Integer, Sequence("foo_id_seq"), primary_key=True), Column("valid_from_date", Date(), nullable=True), Column("valid_thru_date", Date(), nullable=True), ExcludeConstraint( (literal_column("daterange(valid_from_date, valid_thru_date, '[]')"), '&&'), where=column("valid_from_date") <= column("valid_thru_date"), name='ex_mytable_valid_date_range', deferrable=True, initially='deferred' ) ) meta.create_all(testing.db) try: meta2 = MetaData() table_c = table.tometadata(meta2) finally: meta.drop_all(testing.db) ``` -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/c7824a53-f4b9-4707-9577-8896d953820bn%40googlegroups.com.