| 3517 | |
| 3518 | def _single_parent_validator(desc, prop): |
| 3519 | def _do_check(state, value, oldvalue, initiator): |
| 3520 | if value is not None and initiator.key == prop.key: |
| 3521 | hasparent = initiator.hasparent(attributes.instance_state(value)) |
| 3522 | if hasparent and oldvalue is not value: |
| 3523 | raise sa_exc.InvalidRequestError( |
| 3524 | "Instance %s is already associated with an instance " |
| 3525 | "of %s via its %s attribute, and is only allowed a " |
| 3526 | "single parent." |
| 3527 | % (orm_util.instance_str(value), state.class_, prop), |
| 3528 | code="bbf1", |
| 3529 | ) |
| 3530 | return value |
| 3531 | |
| 3532 | def append(state, value, initiator): |
| 3533 | return _do_check(state, value, None, initiator) |