The discussion revolves around an error encountered when trying to move a subcategory to the top level with a duplicate name in Discourse 1.4 Beta 6. anon21958287 reports receiving a “Sorry an error has occurred” message with a 422 status code in Chrome’s dev tools.
riking shares the validation logic around parent categories and suggests that the error may be due to another top-level category with the same name. This is later confirmed by anon21958287, who reveals that a duplicate category was created during an import.
On 1.4 Beta 6, I tried to move a category with a parent to be its own top level category. I get an error message in the dialog (“Sorry an error has occurred”). Chrome’s dev tools say:
Failed to load resource: the server responded with a status of 422 (Unprocessable Entity)
Here’s the validation logic around parent categories:
def parent_category_validator
if parent_category_id
errors.add(:base, I18n.t("category.errors.self_parent")) if parent_category_id == id
errors.add(:base, I18n.t("category.errors.uncategorized_parent")) if uncategorized?
grandfather_id = Category.where(id: parent_category_id).pluck(:parent_category_id).first
errors.add(:base, I18n.t("category.errors.depth")) if grandfather_id
end
end
That shouldn’t trigger when making the parent nil.