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

Method _configure_property

lib/sqlalchemy/orm/mapper.py:2090–2266  ·  view source on GitHub ↗
(
        self,
        key: str,
        prop_arg: Union[KeyedColumnElement[Any], MapperProperty[Any]],
        *,
        init: bool = True,
        setparent: bool = True,
        warn_for_existing: bool = False,
    )

Source from the content-addressed store, hash-verified

2088
2089 @util.preload_module("sqlalchemy.orm.descriptor_props")
2090 def _configure_property(
2091 self,
2092 key: str,
2093 prop_arg: Union[KeyedColumnElement[Any], MapperProperty[Any]],
2094 *,
2095 init: bool = True,
2096 setparent: bool = True,
2097 warn_for_existing: bool = False,
2098 ) -> MapperProperty[Any]:
2099 descriptor_props = util.preloaded.orm_descriptor_props
2100 self._log(
2101 "_configure_property(%s, %s)", key, prop_arg.__class__.__name__
2102 )
2103
2104 # early setup mode - don't assign any props, only
2105 # ensure a Column is turned into a ColumnProperty.
2106 # see #12858
2107 early_setup = not hasattr(self, "_props")
2108
2109 if not isinstance(prop_arg, MapperProperty):
2110 prop: MapperProperty[Any] = self._property_from_column(
2111 key, prop_arg, early_setup
2112 )
2113 else:
2114 prop = prop_arg
2115
2116 if early_setup:
2117 return prop
2118
2119 if isinstance(prop, properties.ColumnProperty):
2120 col = self.persist_selectable.corresponding_column(prop.columns[0])
2121
2122 # if the column is not present in the mapped table,
2123 # test if a column has been added after the fact to the
2124 # parent table (or their parent, etc.) [ticket:1570]
2125 if col is None and self.inherits:
2126 path = [self]
2127 for m in self.inherits.iterate_to_root():
2128 col = m.local_table.corresponding_column(prop.columns[0])
2129 if col is not None:
2130 for m2 in path:
2131 m2.persist_selectable._refresh_for_new_column(col)
2132 col = self.persist_selectable.corresponding_column(
2133 prop.columns[0]
2134 )
2135 break
2136 path.append(m)
2137
2138 # subquery expression, column not present in the mapped
2139 # selectable.
2140 if col is None:
2141 col = prop.columns[0]
2142
2143 # column is coming in after _readonly_props was
2144 # initialized; check for 'readonly'
2145 if hasattr(self, "_readonly_props") and (
2146 not hasattr(col, "table")
2147 or col.table not in self._cols_by_table

Callers 6

_configure_propertiesMethod · 0.95
add_propertyMethod · 0.95
_generate_backrefMethod · 0.80
set_parentMethod · 0.80

Calls 15

_logMethod · 0.95
_property_from_columnMethod · 0.95
_expire_memoizationsMethod · 0.95
iterate_to_rootMethod · 0.80
corresponding_columnMethod · 0.45
appendMethod · 0.45
addMethod · 0.45
warnMethod · 0.45
set_parentMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected