MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _set_parent

Method _set_parent

lib/sqlalchemy/sql/schema.py:5365–5403  ·  view source on GitHub ↗
(self, parent: SchemaEventTarget, **kw: Any)

Source from the content-addressed store, hash-verified

5363 )
5364
5365 def _set_parent(self, parent: SchemaEventTarget, **kw: Any) -> None:
5366 table = parent
5367 assert isinstance(table, Table)
5368 super()._set_parent(table)
5369
5370 if table.primary_key is not self:
5371 table.constraints.discard(table.primary_key)
5372 table.primary_key = self # type: ignore
5373 table.constraints.add(self)
5374
5375 table_pks = [c for c in table.c if c.primary_key]
5376 if (
5377 self._columns
5378 and table_pks
5379 and set(table_pks) != set(self._columns)
5380 ):
5381 # black could not format these inline
5382 table_pk_str = ", ".join("'%s'" % c.name for c in table_pks)
5383 col_str = ", ".join("'%s'" % c.name for c in self._columns)
5384
5385 util.warn(
5386 f"Table '{table.name}' specifies columns "
5387 f"{table_pk_str} as "
5388 f"primary_key=True, "
5389 f"not matching locally specified columns {col_str}; "
5390 f"setting the "
5391 f"current primary key columns to "
5392 f"{col_str}. "
5393 f"This warning "
5394 f"may become an exception in a future release"
5395 )
5396 table_pks[:] = []
5397
5398 for c in self._columns:
5399 c.primary_key = True
5400 if c._user_defined_nullable is NULL_UNSPECIFIED:
5401 c.nullable = False
5402 if table_pks:
5403 self._columns.extend(table_pks)
5404
5405 def _reload(self, columns: Iterable[Column[Any]]) -> None:
5406 """repopulate this :class:`.PrimaryKeyConstraint` given

Callers

nothing calls this directly

Calls 6

_set_parentMethod · 0.45
discardMethod · 0.45
addMethod · 0.45
joinMethod · 0.45
warnMethod · 0.45
extendMethod · 0.45

Tested by

no test coverage detected