Data storage bug fix #569

pull/570/head^2
dgtlmoon 3 years ago committed by GitHub
parent 014dc61222
commit c0d0424e7e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1028,6 +1028,11 @@ def changedetection_app(config=None, datastore_o=None):
@login_required @login_required
def api_delete(): def api_delete():
uuid = request.args.get('uuid') uuid = request.args.get('uuid')
if uuid != 'all' and not uuid in datastore.data['watching'].keys():
flash('The watch by UUID {} does not exist.'.format(uuid), 'error')
return redirect(url_for('index'))
# More for testing, possible to return the first/only # More for testing, possible to return the first/only
if uuid == 'first': if uuid == 'first':
uuid = list(datastore.data['watching'].keys()).pop() uuid = list(datastore.data['watching'].keys()).pop()

@ -22,7 +22,8 @@ class model(dict):
'newest_history_key': 0, 'newest_history_key': 0,
'title': None, 'title': None,
'previous_md5': False, 'previous_md5': False,
'uuid': str(uuid_builder.uuid4()), # UUID not needed, should be generated only as a key
# 'uuid':
'headers': {}, # Extra headers to send 'headers': {}, # Extra headers to send
'body': None, 'body': None,
'method': 'GET', 'method': 'GET',

@ -38,7 +38,8 @@ class ChangeDetectionStore:
self.__data = App.model() self.__data = App.model()
# Base definition for all watchers # Base definition for all watchers
self.generic_definition = Watch.model() # deepcopy part of #569 - not sure why its needed exactly
self.generic_definition = deepcopy(Watch.model())
if path.isfile('changedetectionio/source.txt'): if path.isfile('changedetectionio/source.txt'):
with open('changedetectionio/source.txt') as f: with open('changedetectionio/source.txt') as f:
@ -231,7 +232,7 @@ class ChangeDetectionStore:
del self.data['watching'][uuid] del self.data['watching'][uuid]
self.needs_write = True self.needs_write_urgent = True
# Clone a watch by UUID # Clone a watch by UUID
def clone(self, uuid): def clone(self, uuid):
@ -330,10 +331,13 @@ class ChangeDetectionStore:
with self.lock: with self.lock:
# @todo use a common generic version of this # @todo use a common generic version of this
new_uuid = str(uuid_builder.uuid4()) new_uuid = str(uuid_builder.uuid4())
new_watch = Watch.model({ # #Re 569
# Not sure why deepcopy was needed here, sometimes new watches would appear to already have 'history' set
# I assumed this would instantiate a new object but somehow an existing dict was getting used
new_watch = deepcopy(Watch.model({
'url': url, 'url': url,
'tag': tag 'tag': tag
}) }))
for k in ['uuid', 'history', 'last_checked', 'last_changed', 'newest_history_key', 'previous_md5', 'viewed']: for k in ['uuid', 'history', 'last_checked', 'last_changed', 'newest_history_key', 'previous_md5', 'viewed']:

@ -156,7 +156,7 @@ def test_check_notification(client, live_server):
# cleanup for the next # cleanup for the next
client.get( client.get(
url_for("api_delete", uuid="first"), url_for("api_delete", uuid="all"),
follow_redirects=True follow_redirects=True
) )
@ -172,8 +172,7 @@ def test_notification_validation(client, live_server):
data={"url": test_url, "tag": 'nice one'}, data={"url": test_url, "tag": 'nice one'},
follow_redirects=True follow_redirects=True
) )
with open("xxx.bin", "wb") as f:
f.write(res.data)
assert b"Watch added" in res.data assert b"Watch added" in res.data
# Re #360 some validation # Re #360 some validation
@ -209,6 +208,6 @@ def test_notification_validation(client, live_server):
# cleanup for the next # cleanup for the next
client.get( client.get(
url_for("api_delete", uuid="first"), url_for("api_delete", uuid="all"),
follow_redirects=True follow_redirects=True
) )

Loading…
Cancel
Save