(
self,
key: str,
prop_arg: Union[KeyedColumnElement[Any], MapperProperty[Any]],
*,
init: bool = True,
setparent: bool = True,
warn_for_existing: bool = False,
)
| 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 |
no test coverage detected