Skip to content

Commit

Permalink
Handle duplicate checksum legacy code
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris7 committed Mar 1, 2018
1 parent bcebbfd commit 1074d77
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions wooey/backend/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from pkg_resources import parse_version

from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist
from django.core.exceptions import MultipleObjectsReturned, ObjectDoesNotExist
from django.db import transaction
from django.db.utils import OperationalError
from django.core.files.storage import default_storage
Expand Down Expand Up @@ -236,16 +236,24 @@ def add_wooey_script(script_version=None, script_path=None, group=None, script_n
script_path = script_path or script_version.script_path.name
script_name = script_name or (script_version.script.script_name if script_version else os.path.basename(os.path.splitext(script_path)[0]))
checksum = get_checksum(get_storage_object(script_path).path)
existing_version = None
try:
existing_version = ScriptVersion.objects.get(checksum=checksum, script__script_name=script_name)
if existing_version:
return {
'valid': True,
'errors': None,
'script': existing_version,
}
except ObjectDoesNotExist:
pass
except MultipleObjectsReturned:
# This exists because previous versions did not enforce a checksum, so multiple scriptverisons are
# possible with the same checksum.
existing_version = ScriptVersion.objects.filter(
checksum=checksum,
script__script_name=script_name
).order_by('script_version', 'script_iteration').first()
if existing_version is not None:
return {
'valid': True,
'errors': None,
'script': existing_version,
}

local_storage = get_storage(local=True)
if script_version is not None:
Expand Down

0 comments on commit 1074d77

Please sign in to comment.