Return the boolean value of a `hasparent` flag attached to the given state. The `optimistic` flag determines what the default return value should be if no `hasparent` flag can be located. As this function is used to determine if an instance is an *orphan*, i
(
self, state: InstanceState[Any], optimistic: bool = False
)
| 960 | active_history = property(_get_active_history, _set_active_history) |
| 961 | |
| 962 | def hasparent( |
| 963 | self, state: InstanceState[Any], optimistic: bool = False |
| 964 | ) -> bool: |
| 965 | """Return the boolean value of a `hasparent` flag attached to |
| 966 | the given state. |
| 967 | |
| 968 | The `optimistic` flag determines what the default return value |
| 969 | should be if no `hasparent` flag can be located. |
| 970 | |
| 971 | As this function is used to determine if an instance is an |
| 972 | *orphan*, instances that were loaded from storage should be |
| 973 | assumed to not be orphans, until a True/False value for this |
| 974 | flag is set. |
| 975 | |
| 976 | An instance attribute that is loaded by a callable function |
| 977 | will also not have a `hasparent` flag. |
| 978 | |
| 979 | """ |
| 980 | msg = "This AttributeImpl is not configured to track parents." |
| 981 | assert self.trackparent, msg |
| 982 | |
| 983 | return ( |
| 984 | state.parents.get(id(self.parent_token), optimistic) is not False |
| 985 | ) |
| 986 | |
| 987 | def sethasparent( |
| 988 | self, |