MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _check_attach

Method _check_attach

lib/sqlalchemy/sql/schema.py:4645–4691  ·  lib/sqlalchemy/sql/schema.py::ColumnCollectionMixin._check_attach
(self, evt: bool = False)

Source from the content-addressed store, hash-verified

4643 self._check_attach()
4644
4645 def _check_attach(self, evt: bool = False) -> None:
4646 col_objs = [c for c in self._pending_colargs if isinstance(c, Column)]
4647
4648 cols_w_table = [c for c in col_objs if isinstance(c.table, Table)]
4649
4650 cols_wo_table = set(col_objs).difference(cols_w_table)
4651 if cols_wo_table:
4652 class="cm"># feature #3341 - place event listeners for Column objects
4653 class="cm"># such that when all those cols are attached, we autoattach.
4654 assert not evt, class="st">"Should not reach here on event call"
4655
4656 class="cm"># issue #3411 - don't do the per-column auto-attach if some of the
4657 class="cm"># columns are specified as strings.
4658 has_string_cols = {
4659 c for c in self._pending_colargs if c is not None
4660 }.difference(col_objs)
4661 if not has_string_cols:
4662
4663 def _col_attached(column: Column[Any], table: Table) -> None:
4664 class="cm"># this isinstance() corresponds with the
4665 class="cm"># isinstance() above; only want to count Table-bound
4666 class="cm"># columns
4667 if isinstance(table, Table):
4668 cols_wo_table.discard(column)
4669 if not cols_wo_table:
4670 self._check_attach(evt=True)
4671
4672 self._cols_wo_table = cols_wo_table
4673 for col in cols_wo_table:
4674 col._on_table_attach(_col_attached)
4675 return
4676
4677 columns = cols_w_table
4678
4679 tables = {c.table for c in columns}
4680 if len(tables) == 1:
4681 self._set_parent_with_dispatch(tables.pop())
4682 elif len(tables) > 1 and not self._allow_multiple_tables:
4683 table = columns[0].table
4684 others = [c for c in columns[1:] if c.table is not table]
4685 if others:
4686 class="cm"># black could not format this inline
4687 other_str = class="st">", ".join(class="st">"&class="cm">#x27;%s'" % c for c in others)
4688 raise exc.ArgumentError(
4689 fclass="st">"Column(s) {other_str} "
4690 fclass="st">"are not part of table &class="cm">#x27;{table.description}'."
4691 )
4692
4693 @util.ro_memoized_property
4694 def columns(self) -> ReadOnlyColumnCollection[str, Column[Any]]:

Callers 2

__init__Method · 0.95
_col_attachedMethod · 0.95

Calls 5

_on_table_attachMethod · 0.80
differenceMethod · 0.45
popMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected