MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _adapt_element

Method _adapt_element

lib/sqlalchemy/orm/util.py:1196–1228  ·  view source on GitHub ↗
(
        self, expr: _ORMCOLEXPR, key: Optional[str] = None
    )

Source from the content-addressed store, hash-verified

1194 )._aliased_insp
1195
1196 def _adapt_element(
1197 self, expr: _ORMCOLEXPR, key: Optional[str] = None
1198 ) -> _ORMCOLEXPR:
1199 assert isinstance(expr, ColumnElement)
1200 d: Dict[str, Any] = {
1201 "parententity": self,
1202 "parentmapper": self.mapper,
1203 }
1204 if key:
1205 d["proxy_key"] = key
1206
1207 # userspace adapt of an attribute from AliasedClass; validate that
1208 # it actually was present
1209 adapted = self._adapter.adapt_check_present(expr)
1210 if adapted is None:
1211 adapted = expr
1212 if self._adapter.adapt_on_names:
1213 util.warn_limited(
1214 "Did not locate an expression in selectable for "
1215 "attribute %r; ensure name is correct in expression",
1216 (key,),
1217 )
1218 else:
1219 util.warn_limited(
1220 "Did not locate an expression in selectable for "
1221 "attribute %r; to match by name, use the "
1222 "adapt_on_names parameter",
1223 (key,),
1224 )
1225
1226 return adapted._annotate(d)._set_propagate_attrs(
1227 {"compile_state_plugin": "orm", "plugin_subject": self}
1228 )
1229
1230 if TYPE_CHECKING:
1231 # establish compatibility with the _ORMAdapterProto protocol,

Callers 3

_init_for_joinMethod · 0.80
_load_for_pathMethod · 0.80

Calls 3

adapt_check_presentMethod · 0.45
_set_propagate_attrsMethod · 0.45
_annotateMethod · 0.45

Tested by

no test coverage detected