Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2 fields with same handle #7780

Closed
SayChi opened this issue Apr 9, 2021 · 1 comment
Closed

2 fields with same handle #7780

SayChi opened this issue Apr 9, 2021 · 1 comment
Labels

Comments

@SayChi
Copy link

SayChi commented Apr 9, 2021

Description

I just noticed that somehow we got 2 fields in our project with the same handle (and all other settings, except for the group). I'm not sure how this happened, i think we messed something up in a merge. (I checked our config files, and it's there twice too)

image

But my point for this issue is that duplicate handles sound like a really bad time somewhere down the line. I guess the .yaml are taken as absolute truth. Not sure if there is any kind of validation in there, but it might be worthwhile to check for duplicate field handles before letting the user apply the config files?

Steps to reproduce

I haven't tried this, but this is what i imagine could force this issue

  1. Duplicate one of the files in config\project\fields
  2. Change the uid of the duplicated file
  3. Apply config files to project

Additional info

  • Craft version: 3.6.11.2
  • PHP version: 7.4.12
  • Database driver & version: MySQL 5.7.26
  • Plugins & versions: irrelevant, i think
@SayChi SayChi added the bug label Apr 9, 2021
@brandonkelly
Copy link
Member

Most likely happened as a result of a bad project config merge. You should be able to find out how it happened by looking at the Git history of config/project/. The YAML files are considered the source of truth, so any validation that needs to occur happens before the project config is modified / written out in the first place.

Yeah it’s problematic, since now if you delete one of those fields, Craft is going to delete the content column that they both currently share. (This will be resolved for new fields created after updating to Craft 3.7 thanks to column suffixes (#6922).)

If the change hasn’t hit production yet, then the best way to fix is to re-run through the project config environment setup instructions, and then carefully merge in any project config changes that have happened on dev environments since the last time production was updated.

Otherwise, try this:

  1. Go into your content table and find the column that contains the correct data for the field. (Note that it may end in _old.)
  2. Rename the column, giving it a _tmp suffix.
  3. Delete or rename one of the two duplicate fields from the control panel.
  4. Rename the *_tmp column back to whatever it really should be (e.g. field_theFieldHandle).

On other environments, either share a DB backup with them from the first environment, or go through a similar procedure – steps 1 and 2, then apply the incoming project config YAML produced by the first environment, then step 4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants