Fix crash on create package error due to missing rollback

This commit is contained in:
rubenwardy
2025-08-16 16:45:30 +01:00
parent a6fccc7c58
commit 66f918c1bf
2 changed files with 8 additions and 5 deletions

View File

@@ -306,10 +306,6 @@ def handle_create_edit(package: typing.Optional[Package], form: PackageForm, aut
"translation_url": form.translation_url.data,
})
if wasNew:
msg = f"Created package {author.username}/{form.name.data}"
add_audit_log(AuditSeverity.NORMAL, current_user, msg, package.get_url("packages.view"), package)
if wasNew and package.repo is not None:
import_repo_screenshot.delay(package.id)
@@ -322,6 +318,7 @@ def handle_create_edit(package: typing.Optional[Package], form: PackageForm, aut
return redirect(next_url)
except LogicError as e:
flash(e.message, "danger")
db.session.rollback()
@bp.route("/packages/new/", methods=["GET", "POST"])

View File

@@ -136,6 +136,9 @@ def do_edit_package(user: User, package: Package, was_new: bool, was_web: bool,
for alias, to in ALIASES.items():
if alias in data:
if to in data and data[to] != data[alias]:
raise LogicError(403, f"Aliased field ({alias}) does not match new field ({to})")
data[to] = data[alias]
validate(data)
@@ -207,7 +210,10 @@ def do_edit_package(user: User, package: Package, was_new: bool, was_web: bool,
package.content_warnings.append(warning)
was_modified = was_new
if not was_new:
if was_new:
msg = f"Created package {package.author.username}/{package.name}"
add_audit_log(AuditSeverity.NORMAL, user, msg, package.get_url("packages.view"), package)
else:
after_dict = package.as_dict("/")
diff = diff_dictionaries(before_dict, after_dict)
was_modified = len(diff) > 0