MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _make_proxy

Method _make_proxy

lib/sqlalchemy/sql/schema.py:2898–2979  ·  view source on GitHub ↗

Create a *proxy* for this column. This is a copy of this ``Column`` referenced by a different parent (such as an alias or select statement). The column should be used only in select scenarios, as its full DDL/default information is not transferred.

(
        self,
        selectable: FromClause,
        primary_key: ColumnSet,
        foreign_keys: Set[KeyedColumnElement[Any]],
        name: Optional[str] = None,
        key: Optional[str] = None,
        name_is_truncatable: bool = False,
        compound_select_cols: Optional[
            _typing_Sequence[ColumnElement[Any]]
        ] = None,
        **kw: Any,
    )

Source from the content-addressed store, hash-verified

2896 new_fk._set_parent(other)
2897
2898 def _make_proxy(
2899 self,
2900 selectable: FromClause,
2901 primary_key: ColumnSet,
2902 foreign_keys: Set[KeyedColumnElement[Any]],
2903 name: Optional[str] = None,
2904 key: Optional[str] = None,
2905 name_is_truncatable: bool = False,
2906 compound_select_cols: Optional[
2907 _typing_Sequence[ColumnElement[Any]]
2908 ] = None,
2909 **kw: Any,
2910 ) -> Tuple[str, ColumnClause[_T]]:
2911 """Create a *proxy* for this column.
2912
2913 This is a copy of this ``Column`` referenced by a different parent
2914 (such as an alias or select statement). The column should
2915 be used only in select scenarios, as its full DDL/default
2916 information is not transferred.
2917
2918 """
2919
2920 fk = [
2921 ForeignKey(
2922 col if col is not None else f._colspec,
2923 _unresolvable=col is None,
2924 _constraint=f.constraint,
2925 )
2926 for f, col in [
2927 (fk, fk._resolve_column(raiseerr=False))
2928 for fk in self.foreign_keys
2929 ]
2930 ]
2931
2932 if name is None and self.name is None:
2933 raise exc.InvalidRequestError(
2934 "Cannot initialize a sub-selectable"
2935 " with this Column object until its 'name' has "
2936 "been assigned."
2937 )
2938 try:
2939 c = self._constructor(
2940 (
2941 coercions.expect(
2942 roles.TruncatedLabelRole, name if name else self.name
2943 )
2944 if name_is_truncatable
2945 else (name or self.name)
2946 ),
2947 self.type,
2948 # this may actually be ._proxy_key when the key is incoming
2949 key=key if key else name if name else self.key,
2950 primary_key=self.primary_key,
2951 nullable=self.nullable,
2952 _proxies=(
2953 list(compound_select_cols)
2954 if compound_select_cols
2955 else [self]

Calls 6

ForeignKeyClass · 0.85
_resolve_columnMethod · 0.80
_constructorMethod · 0.45
getMethod · 0.45
addMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected