en
Language
  • en
  • cs
  • hu
  • de
  • fr
  • es
  • br
  • ru
  • kr
  • jp
AI translation
  • it
  • pl
  • tr

Error When Creating a New Item in Administration Categories

Introduction

This article explains the cause of an error that appears when creating a new item in Administration → Categories in Easy8. The issue occurs due to a combination of protected attributes in models and a known MySQL bug. Understanding this helps administrators avoid and resolve the problem efficiently.

Target Audience

  • Administrator

Understanding the Error When Creating New Enumeration Items

Definition

When you create a new category (e.g., Issue Priority) in Administration → Categories, an error message may appear and the action fails. This is triggered by a backend conflict involving:

  • Rails model attribute protection
  • Invalid subquery structure in MySQL version 5.7.6 to 5.7.10

How It Works

When a new enumeration item is submitted, the following happens in the backend:

  1. Rails attempts to create a new object of type IssuePriority.
  2. The model has protected attributes, such as type, which cannot be mass-assigned.
  3. At the same time, MySQL executes a complex query to update the position of enumeration items. This query includes a subquery from the same table (enumerations), which is not allowed in certain MySQL versions.

Here is the failing query pattern:

UPDATE enumerations
SET position = COALESCE((
  SELECT position FROM (
    SELECT id, position FROM enumerations
  ) AS parent
  WHERE parent_id = parent.id
), 1)
WHERE enumerations.type IN ('IssuePriority') AND (enumerations.parent_id IS NOT NULL)
ORDER BY enumerations.position ASC;

This structure causes a 500 Internal Server Error in MySQL versions 5.7.6 to 5.7.10.

Practical Example of the Error

Sample log output:

WARNING: Can't mass-assign protected attributes for IssuePriority: type
...
ActiveRecord::StatementInvalid (Mysql2::Error: You can't specify target table 'enumerations' for update in FROM clause)

Why This Happens

The combination of:

  • Rails mass-assignment protection blocking the type attribute
  • MySQL bug in subqueries on same table in UPDATE statements

causes this operation to fail.

Fix and MySQL Version Notes

The issue is related to a known bug in MySQL. It was:

  • Introduced in version 5.7.6
  • Fixed in version 5.7.11

See official bug report:
MySQL Bug #79333

Search for fix in:
MySQL 5.7.11 release notes

Conclusion

The error when creating a new category in Easy8 is due to a MySQL bug in versions 5.7.6–5.7.10 and protected model attributes. To fix the issue, upgrade your MySQL server to at least version 5.7.11 where this behavior is corrected.

Further Reading

Try Easy8 in 30 days free trial

Access all features, SSL protected, no credit card required.