MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / set

Method set

lib/sqlalchemy/orm/attributes.py:1456–1502  ·  view source on GitHub ↗

Set a value on the given InstanceState.

(
        self,
        state: InstanceState[Any],
        dict_: _InstanceDict,
        value: Any,
        initiator: Optional[AttributeEventToken] = None,
        passive: PassiveFlag = PASSIVE_OFF,
        check_old: Any = None,
        pop: bool = False,
    )

Source from the content-addressed store, hash-verified

1454 return ret
1455
1456 def set(
1457 self,
1458 state: InstanceState[Any],
1459 dict_: _InstanceDict,
1460 value: Any,
1461 initiator: Optional[AttributeEventToken] = None,
1462 passive: PassiveFlag = PASSIVE_OFF,
1463 check_old: Any = None,
1464 pop: bool = False,
1465 ) -> None:
1466 """Set a value on the given InstanceState."""
1467
1468 if value is DONT_SET:
1469 return
1470
1471 if self.dispatch._active_history:
1472 old = self.get(
1473 state,
1474 dict_,
1475 passive=PASSIVE_ONLY_PERSISTENT
1476 | NO_AUTOFLUSH
1477 | LOAD_AGAINST_COMMITTED,
1478 )
1479 else:
1480 old = self.get(
1481 state,
1482 dict_,
1483 passive=PASSIVE_NO_FETCH ^ INIT_OK
1484 | LOAD_AGAINST_COMMITTED
1485 | NO_RAISE,
1486 )
1487
1488 if (
1489 check_old is not None
1490 and old is not PASSIVE_NO_RESULT
1491 and check_old is not old
1492 ):
1493 if pop:
1494 return
1495 else:
1496 raise ValueError(
1497 "Object %s not associated with %s on attribute '%s'"
1498 % (instance_str(check_old), state_str(state), self.key)
1499 )
1500
1501 value = self.fire_replace_event(state, dict_, value, old, initiator)
1502 dict_[self.key] = value
1503
1504 def fire_remove_event(
1505 self,

Callers

nothing calls this directly

Calls 4

fire_replace_eventMethod · 0.95
instance_strFunction · 0.85
state_strFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected