Fix crash when generating diff on new package

This commit is contained in:
rubenwardy 2023-05-12 15:53:06 +01:00
parent dee9959fda
commit 35afd50f3d

@ -113,6 +113,8 @@ 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 = None
if not was_new:
before_dict = package.getAsDictionary("/")
for alias, to in ALIASES.items():
@ -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)
if not was_new:
after_dict = package.getAsDictionary("/")
diff = diff_dictionaries(before_dict, after_dict)
if not was_new:
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 + "]"