Error moving sub category to top level with duplicate name

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)

2 Likes

What does this mean? Can you describe it in step by step fashion?

Click the “Edit” button on a category page. There’s a dropdown for “Parent Category.” I selected “no parent.”

1 Like

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.

We also have this:

  validates :name, if: Proc.new { |c| c.new_record? || c.name_changed? },
                   presence: true,
                   uniqueness: { scope: :parent_category_id, case_sensitive: false },
                   length: { in: 1..50 }

Is there, perhaps, another top-level category with the same name?

2 Likes

Ah…yes, there is. One was created when we imported the old stuff.

2 Likes