represents a scalar-holding InstrumentedAttribute, where the target object is also instrumented. Adds events to delete/set operations.
| 1337 | |
| 1338 | |
| 1339 | class _ScalarObjectAttributeImpl(_ScalarAttributeImpl): |
| 1340 | """represents a scalar-holding InstrumentedAttribute, |
| 1341 | where the target object is also instrumented. |
| 1342 | |
| 1343 | Adds events to delete/set operations. |
| 1344 | |
| 1345 | """ |
| 1346 | |
| 1347 | default_accepts_scalar_loader = False |
| 1348 | uses_objects = True |
| 1349 | supports_population = True |
| 1350 | collection = False |
| 1351 | |
| 1352 | __slots__ = () |
| 1353 | |
| 1354 | def delete(self, state: InstanceState[Any], dict_: _InstanceDict) -> None: |
| 1355 | if self.dispatch._active_history: |
| 1356 | old = self.get( |
| 1357 | state, |
| 1358 | dict_, |
| 1359 | passive=PASSIVE_ONLY_PERSISTENT |
| 1360 | | NO_AUTOFLUSH |
| 1361 | | LOAD_AGAINST_COMMITTED, |
| 1362 | ) |
| 1363 | else: |
| 1364 | old = self.get( |
| 1365 | state, |
| 1366 | dict_, |
| 1367 | passive=PASSIVE_NO_FETCH ^ INIT_OK |
| 1368 | | LOAD_AGAINST_COMMITTED |
| 1369 | | NO_RAISE, |
| 1370 | ) |
| 1371 | |
| 1372 | self.fire_remove_event(state, dict_, old, self._remove_token) |
| 1373 | |
| 1374 | existing = dict_.pop(self.key, NO_VALUE) |
| 1375 | |
| 1376 | # if the attribute is expired, we currently have no way to tell |
| 1377 | # that an object-attribute was expired vs. not loaded. So |
| 1378 | # for this test, we look to see if the object has a DB identity. |
| 1379 | if ( |
| 1380 | existing is NO_VALUE |
| 1381 | and old is not PASSIVE_NO_RESULT |
| 1382 | and state.key is None |
| 1383 | ): |
| 1384 | raise AttributeError("%s object does not have a value" % self) |
| 1385 | |
| 1386 | def get_history( |
| 1387 | self, |
| 1388 | state: InstanceState[Any], |
| 1389 | dict_: _InstanceDict, |
| 1390 | passive: PassiveFlag = PASSIVE_OFF, |
| 1391 | ) -> History: |
| 1392 | if self.key in dict_: |
| 1393 | current = dict_[self.key] |
| 1394 | else: |
| 1395 | if passive & INIT_OK: |
| 1396 | passive ^= INIT_OK |
no outgoing calls
no test coverage detected