From 35afd50f3d005374353fea0fd06158a1758cf3a8 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Fri, 12 May 2023 15:53:06 +0100 Subject: [PATCH] Fix crash when generating diff on new package --- app/logic/packages.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/app/logic/packages.py b/app/logic/packages.py index f5fab6c2..4309d5c5 100644 --- a/app/logic/packages.py +++ b/app/logic/packages.py @@ -113,7 +113,9 @@ def do_edit_package(user: User, package: Package, was_new: bool, was_web: bool, not package.checkPerm(user, Permission.CHANGE_NAME): raise LogicError(403, lazy_gettext("You don't have permission to change the package name")) - before_dict = package.getAsDictionary("/") + before_dict = None + if not was_new: + before_dict = package.getAsDictionary("/") for alias, to in ALIASES.items(): if alias in data: @@ -190,16 +192,16 @@ def do_edit_package(user: User, package: Package, was_new: bool, was_web: bool, raise LogicError(400, "Unknown warning: " + warning_id) package.content_warnings.append(warning) - after_dict = package.getAsDictionary("/") - diff = diff_dictionaries(before_dict, after_dict) - if not was_new: + after_dict = package.getAsDictionary("/") + diff = diff_dictionaries(before_dict, after_dict) + if reason is None: msg = "Edited {}".format(package.title) else: msg = "Edited {} ({})".format(package.title, reason) - diff_desc = describe_difference(diff, 100 - len(msg) - 3) + diff_desc = describe_difference(diff, 100 - len(msg) - 3) if diff else None if diff_desc: msg += " [" + diff_desc + "]"