From 85260144ef668d3a2565c76064fc9c6ea591af06 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Sun, 20 Sep 2020 11:16:07 -0700 Subject: [PATCH] Add attribute deleted to all objects, for held instances. If an instance is being held in two places, and then one of them calls delete(), the other can check deleted before doing anything with the object. --- etiquette/objects.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/etiquette/objects.py b/etiquette/objects.py index 91eda0f..b23e050 100644 --- a/etiquette/objects.py +++ b/etiquette/objects.py @@ -33,6 +33,7 @@ class ObjectBase: def __init__(self, photodb): super().__init__() self.photodb = photodb + self.deleted = False def __eq__(self, other): return ( @@ -157,6 +158,7 @@ class GroupableMixin: # issues of recursion. self.photodb.sql_delete(table=self.group_table, pairs={'memberid': self.id}) self._uncache() + self.deleted = True def get_children(self): child_rows = self.photodb.sql_select( @@ -372,6 +374,7 @@ class Album(ObjectBase, GroupableMixin): self.photodb.sql_delete(table='album_photo_rel', pairs={'albumid': self.id}) self.photodb.sql_delete(table='albums', pairs={'id': self.id}) self._uncache() + self.deleted = True @property def display_name(self): @@ -596,6 +599,7 @@ class Bookmark(ObjectBase): def delete(self): self.photodb.sql_delete(table='bookmarks', pairs={'id': self.id}) self._uncache() + self.deleted = True @decorators.required_feature('bookmark.edit') @decorators.transaction @@ -775,6 +779,7 @@ class Photo(ObjectBase): queue_action = {'action': action, 'args': [path]} self.photodb.on_commit_queue.append(queue_action) self._uncache() + self.deleted = True @property def duration_string(self): @@ -1365,6 +1370,7 @@ class Tag(ObjectBase, GroupableMixin): self.photodb.sql_delete(table='tags', pairs={'id': self.id}) self.photodb.caches['tag_exports'].clear() self._uncache() + self.deleted = True @decorators.required_feature('tag.edit') @decorators.transaction