| 4980 | ) |
| 4981 | |
| 4982 | def _set_parent(self, parent: SchemaEventTarget, **kw: Any) -> None: |
| 4983 | table = parent |
| 4984 | assert isinstance(table, Table) |
| 4985 | super()._set_parent(table) |
| 4986 | |
| 4987 | if table.primary_key is not self: |
| 4988 | table.constraints.discard(table.primary_key) |
| 4989 | table.primary_key = self # type: ignore |
| 4990 | table.constraints.add(self) |
| 4991 | |
| 4992 | table_pks = [c for c in table.c if c.primary_key] |
| 4993 | if ( |
| 4994 | self._columns |
| 4995 | and table_pks |
| 4996 | and set(table_pks) != set(self._columns) |
| 4997 | ): |
| 4998 | # black could not format these inline |
| 4999 | table_pk_str = ", ".join("'%s'" % c.name for c in table_pks) |
| 5000 | col_str = ", ".join("'%s'" % c.name for c in self._columns) |
| 5001 | |
| 5002 | util.warn( |
| 5003 | f"Table '{table.name}' specifies columns " |
| 5004 | f"{table_pk_str} as " |
| 5005 | f"primary_key=True, " |
| 5006 | f"not matching locally specified columns {col_str}; " |
| 5007 | f"setting the " |
| 5008 | f"current primary key columns to " |
| 5009 | f"{col_str}. " |
| 5010 | f"This warning " |
| 5011 | f"may become an exception in a future release" |
| 5012 | ) |
| 5013 | table_pks[:] = [] |
| 5014 | |
| 5015 | for c in self._columns: |
| 5016 | c.primary_key = True |
| 5017 | if c._user_defined_nullable is NULL_UNSPECIFIED: |
| 5018 | c.nullable = False |
| 5019 | if table_pks: |
| 5020 | self._columns.extend(table_pks) |
| 5021 | |
| 5022 | def _reload(self, columns: Iterable[Column[Any]]) -> None: |
| 5023 | """repopulate this :class:`.PrimaryKeyConstraint` given |