Don't update self.attribute until sql_update goes through.

This commit is contained in:
voussoir 2020-09-17 20:44:33 -07:00
parent a093dc273c
commit 40e458e713

View file

@ -390,17 +390,19 @@ class Album(ObjectBase, GroupableMixin):
return return
if title is not None: if title is not None:
self.title = self.normalize_title(title) title = self.normalize_title(title)
if description is not None: if description is not None:
self.description = self.normalize_description(description) description = self.normalize_description(description)
data = { data = {
'id': self.id, 'id': self.id,
'title': self.title, 'title': title,
'description': self.description, 'description': description,
} }
self.photodb.sql_update(table='albums', pairs=data, where_key='id') self.photodb.sql_update(table='albums', pairs=data, where_key='id')
self.title = title
self.description = description
def get_associated_directories(self): def get_associated_directories(self):
directory_rows = self.photodb.sql_select( directory_rows = self.photodb.sql_select(
@ -608,18 +610,19 @@ class Bookmark(ObjectBase):
return return
if title is not None: if title is not None:
self.title = self.normalize_title(title) title = self.normalize_title(title)
if url is not None: if url is not None:
self.url = self.normalize_url(url) url = self.normalize_url(url)
data = { data = {
'id': self.id, 'id': self.id,
'title': self.title, 'title': title,
'url': self.url, 'url': url,
} }
self.photodb.sql_update(table='bookmarks', pairs=data, where_key='id') self.photodb.sql_update(table='bookmarks', pairs=data, where_key='id')
self.title = title
self.url = url
class Photo(ObjectBase): class Photo(ObjectBase):
''' '''
@ -1149,7 +1152,6 @@ class Photo(ObjectBase):
'searchhidden': bool(searchhidden), 'searchhidden': bool(searchhidden),
} }
self.photodb.sql_update(table='photos', pairs=data, where_key='id') self.photodb.sql_update(table='photos', pairs=data, where_key='id')
self.searchhidden = searchhidden self.searchhidden = searchhidden
@decorators.required_feature('photo.edit') @decorators.required_feature('photo.edit')
@ -1162,6 +1164,7 @@ class Photo(ObjectBase):
'override_filename': new_filename, 'override_filename': new_filename,
} }
self.photodb.sql_update(table='photos', pairs=data, where_key='id') self.photodb.sql_update(table='photos', pairs=data, where_key='id')
self.basename = override_filename
self.__reinit__() self.__reinit__()
@ -1376,13 +1379,14 @@ class Tag(ObjectBase, GroupableMixin):
if description is None: if description is None:
return return
self.description = self.normalize_description(description) description = self.normalize_description(description)
data = { data = {
'id': self.id, 'id': self.id,
'description': self.description 'description': description,
} }
self.photodb.sql_update(table='tags', pairs=data, where_key='id') self.photodb.sql_update(table='tags', pairs=data, where_key='id')
self.description = description
self._uncache() self._uncache()
@ -1523,7 +1527,6 @@ class User(ObjectBase):
'display_name': display_name, 'display_name': display_name,
} }
self.photodb.sql_update(table='users', pairs=data, where_key='id') self.photodb.sql_update(table='users', pairs=data, where_key='id')
self._display_name = display_name self._display_name = display_name