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