MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _configure_property

Method _configure_property

lib/sqlalchemy/orm/mapper.py:2019–2194  ·  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

2017
2018 @util.preload_module("sqlalchemy.orm.descriptor_props")
2019 def _configure_property(
2020 self,
2021 key: str,
2022 prop_arg: Union[KeyedColumnElement[Any], MapperProperty[Any]],
2023 *,
2024 init: bool = True,
2025 setparent: bool = True,
2026 warn_for_existing: bool = False,
2027 ) -> MapperProperty[Any]:
2028 descriptor_props = util.preloaded.orm_descriptor_props
2029 self._log(
2030 "_configure_property(%s, %s)", key, prop_arg.__class__.__name__
2031 )
2032
2033 # early setup mode - don't assign any props, only
2034 # ensure a Column is turned into a ColumnProperty.
2035 # see #12858
2036 early_setup = not hasattr(self, "_props")
2037
2038 if not isinstance(prop_arg, MapperProperty):
2039 prop: MapperProperty[Any] = self._property_from_column(
2040 key, prop_arg, early_setup
2041 )
2042 else:
2043 prop = prop_arg
2044
2045 if early_setup:
2046 return prop
2047
2048 if isinstance(prop, properties.ColumnProperty):
2049 col = self.persist_selectable.corresponding_column(prop.columns[0])
2050
2051 # if the column is not present in the mapped table,
2052 # test if a column has been added after the fact to the
2053 # parent table (or their parent, etc.) [ticket:1570]
2054 if col is None and self.inherits:
2055 path = [self]
2056 for m in self.inherits.iterate_to_root():
2057 col = m.local_table.corresponding_column(prop.columns[0])
2058 if col is not None:
2059 for m2 in path:
2060 m2.persist_selectable._refresh_for_new_column(col)
2061 col = self.persist_selectable.corresponding_column(
2062 prop.columns[0]
2063 )
2064 break
2065 path.append(m)
2066
2067 # subquery expression, column not present in the mapped
2068 # selectable.
2069 if col is None:
2070 col = prop.columns[0]
2071
2072 # column is coming in after _readonly_props was
2073 # initialized; check for 'readonly'
2074 if hasattr(self, "_readonly_props") and (
2075 not hasattr(col, "table")
2076 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