(
prop,
mapper,
useobject,
compare_function=None,
typecallable=None,
callable_=None,
proxy_property=None,
active_history=False,
impl_class=None,
default_scalar_value=None,
**kw,
)
| 67 | |
| 68 | |
| 69 | def _register_attribute( |
| 70 | prop, |
| 71 | mapper, |
| 72 | useobject, |
| 73 | compare_function=None, |
| 74 | typecallable=None, |
| 75 | callable_=None, |
| 76 | proxy_property=None, |
| 77 | active_history=False, |
| 78 | impl_class=None, |
| 79 | default_scalar_value=None, |
| 80 | **kw, |
| 81 | ): |
| 82 | listen_hooks = [] |
| 83 | |
| 84 | uselist = useobject and prop.uselist |
| 85 | |
| 86 | if useobject and prop.single_parent: |
| 87 | listen_hooks.append(_single_parent_validator) |
| 88 | |
| 89 | if prop.key in prop.parent.validators: |
| 90 | fn, opts = prop.parent.validators[prop.key] |
| 91 | listen_hooks.append( |
| 92 | lambda desc, prop: orm_util._validator_events( |
| 93 | desc, prop.key, fn, **opts |
| 94 | ) |
| 95 | ) |
| 96 | |
| 97 | if useobject: |
| 98 | listen_hooks.append(unitofwork._track_cascade_events) |
| 99 | |
| 100 | # need to assemble backref listeners |
| 101 | # after the singleparentvalidator, mapper validator |
| 102 | if useobject: |
| 103 | backref = prop.back_populates |
| 104 | if backref and prop._effective_sync_backref: |
| 105 | listen_hooks.append( |
| 106 | lambda desc, prop: attributes._backref_listeners( |
| 107 | desc, backref, uselist |
| 108 | ) |
| 109 | ) |
| 110 | |
| 111 | # a single MapperProperty is shared down a class inheritance |
| 112 | # hierarchy, so we set up attribute instrumentation and backref event |
| 113 | # for each mapper down the hierarchy. |
| 114 | |
| 115 | # typically, "mapper" is the same as prop.parent, due to the way |
| 116 | # the configure_mappers() process runs, however this is not strongly |
| 117 | # enforced, and in the case of a second configure_mappers() run the |
| 118 | # mapper here might not be prop.parent; also, a subclass mapper may |
| 119 | # be called here before a superclass mapper. That is, can't depend |
| 120 | # on mappers not already being set up so we have to check each one. |
| 121 | |
| 122 | for m in mapper.self_and_descendants: |
| 123 | if prop is m._props.get( |
| 124 | prop.key |
| 125 | ) and not m.class_manager._attr_has_impl(prop.key): |
| 126 | desc = attributes._register_attribute_impl( |
no test coverage detected