MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / _check_attach

Method _check_attach

lib/sqlalchemy/sql/schema.py:4265–4311  ·  view source on GitHub ↗
(self, evt: bool = False)

Source from the content-addressed store, hash-verified

4263 self._check_attach()
4264
4265 def _check_attach(self, evt: bool = False) -> None:
4266 col_objs = [c for c in self._pending_colargs if isinstance(c, Column)]
4267
4268 cols_w_table = [c for c in col_objs if isinstance(c.table, Table)]
4269
4270 cols_wo_table = set(col_objs).difference(cols_w_table)
4271 if cols_wo_table:
4272 # feature #3341 - place event listeners for Column objects
4273 # such that when all those cols are attached, we autoattach.
4274 assert not evt, "Should not reach here on event call"
4275
4276 # issue #3411 - don't do the per-column auto-attach if some of the
4277 # columns are specified as strings.
4278 has_string_cols = {
4279 c for c in self._pending_colargs if c is not None
4280 }.difference(col_objs)
4281 if not has_string_cols:
4282
4283 def _col_attached(column: Column[Any], table: Table) -> None:
4284 # this isinstance() corresponds with the
4285 # isinstance() above; only want to count Table-bound
4286 # columns
4287 if isinstance(table, Table):
4288 cols_wo_table.discard(column)
4289 if not cols_wo_table:
4290 self._check_attach(evt=True)
4291
4292 self._cols_wo_table = cols_wo_table
4293 for col in cols_wo_table:
4294 col._on_table_attach(_col_attached)
4295 return
4296
4297 columns = cols_w_table
4298
4299 tables = {c.table for c in columns}
4300 if len(tables) == 1:
4301 self._set_parent_with_dispatch(tables.pop())
4302 elif len(tables) > 1 and not self._allow_multiple_tables:
4303 table = columns[0].table
4304 others = [c for c in columns[1:] if c.table is not table]
4305 if others:
4306 # black could not format this inline
4307 other_str = ", ".join("'%s'" % c for c in others)
4308 raise exc.ArgumentError(
4309 f"Column(s) {other_str} "
4310 f"are not part of table '{table.description}'."
4311 )
4312
4313 @util.ro_memoized_property
4314 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