Fix #4877: Error when tagging favgroup:foo when post is already in favgroup:foo

Bug: If a tag edit failed because it contained a metatag that raised an
exception, then a new post version would be created even though the edit
didn't go through. This could happen if the newpool:, fav:, favgroup:,
disapproved:, status:active, or status:banned metatags failed (for
example, because of a privilege error).

Fix: Silently ignore all errors raised when applying metatags. This way
the edit will always succeed, so erroneous post versions won't be created.
This commit is contained in:
evazion
2022-05-02 14:23:01 -05:00
parent 93352b318e
commit d2502a0c40
2 changed files with 65 additions and 18 deletions

View File

@@ -546,6 +546,11 @@ class Post < ApplicationRecord
end
end
rescue
# XXX Silently ignore errors so that the edit doesn't fail. We can't let
# the edit fail because then it will create a new post version even if
# the edit didn't go through.
nil
end
def apply_pre_metatags
@@ -709,6 +714,11 @@ class Post < ApplicationRecord
parent.update_has_children_flag if parent.present?
Post.find(parent_id_before_last_save).update_has_children_flag if parent_id_before_last_save.present?
rescue
# XXX Silently ignore errors so that the edit doesn't fail. We can't let
# the edit fail because then it will create a new post version even if
# the edit didn't go through.
nil
end
def give_favorites_to_parent
@@ -790,6 +800,9 @@ class Post < ApplicationRecord
end
concerning :VersionMethods do
# XXX `create_version` must be called before `apply_post_metatags` because
# `apply_post_metatags` may update the post itself, which will clear all
# changes to the post and make saved_change_to_*? return false.
def create_version(force = false)
if new_record? || saved_change_to_watched_attributes? || force
create_new_version