craftcms / craftcms/cms

Renaming fields in matrix blocks issue

Open
#3,341 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug severity:minor
Dominant language
PHP
Stars
3.6k
Forks
705
Avg merge
1d 5h
Merged PRs (30d)
134

Description

Description

There's a bug in matrix where renaming fields can get a mySQL error under specific circumstances. (possibly not restricted to matrix fields this but that's just where I've experienced it)

Steps to reproduce
  1. create a matrix field and add a block type
  2. create 2 plain text fields in the block, name one heading and one description and save the field
  3. edit the field and rename the first field to description and the second to anything else (rename the field handles too)
  4. the error is that the column matrix_blocktype__description exists already (which of course it does) however we're actually renaming that column too at the same time.

The workaround of course is to rename them one at a time to avoid this collision.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue using the listed matrix-block steps, including swapping the two field names and handles in one save. Trace the field-renaming and database-column update entry points involved in that save. Done means the fields can be renamed simultaneously without a MySQL duplicate-column error, while sequential renaming remains unnecessary.

Written by the indexing model from the issue text.

Assessment

Tech stack
mysql, php
Domain
backend, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.