Cms: Project config - issue with fields with the same handle

Created on 20 Apr 2020  Â·  9Comments  Â·  Source: craftcms/cms

We've run into a few issues with the project config, one scenario:

  1. We removed a Neo field in favor of a matrix field, both with the same handle 'menu' and both attached to a global set. You push the changes, following happens:
    Integrity constraint violation: 1062 Duplicate entry 'menu-global' for key 'fields.fields_handle_context_unq_idx'
bug normal

All 9 comments

@andris-sevcenko this ties into that project.yaml validation we were talking about. Craft should be performing basic validation across the entirety of new configs before syncing changes.

It should be ensuring there are no duplicate names/handles across:

  • sites
  • sections
  • field groups (name only)
  • fields in global context
  • Matrix block types (per Matrix field)
  • Matrix sub-fields (per block type)
  • volumes
  • user groups
  • category groups
  • tag groups
  • global sets
  • image transforms

There should also be an event that gives plugins a chance to add their own checks (e.g. Neo/Super Table should be checking if their own sub-fields’ names & handles are unique).

If there are any errors, they should be logged (and output if it’s a console request), and the sync should be aborted.

Related: #4369

In addition, we sometimes see some issues with the following scenario as well:

  1. We install a plugin locally
  2. Test it, decide not to use it, remove it

If between step 1 and 2 we haven't deployed it, project config tries to remove a plugin on the production that wasn't there in the first place, causing an error.

@lenvanessen I don’t think that’s quite right… Craft will only try to uninstall a plugin per a project.yaml change, if its stored project config previously had a record of the plugin being installed, but the new project.yaml file has it removed. So if you install and then uninstall a plugin before ever pushing to production, then production would never have known about the plugin to begin with.

More likely you did something like this:

  1. Install a plugin on dev
  2. Push changes to prod (including project.yaml and composer.json + composer.lock)
  3. Uninstall plugin on dev and Composer-remove the plugin
  4. Push changes to prod (including project.yaml and composer.json + composer.lock)

If you do that, then Craft won’t be able to successfully uninstall the plugin, because plugins themselves are responsible for their own deinstallation. If the plugin’s files are no longer present (because of it being Composer-removed), then it won’t be around to uninstall itself.

@brandonkelly yes, makes sense.

I probably hit the same bug today.

Renamed the handle of a field used in globals from booking_link to booking_link_general.
Renamed the handle of a field used in different structures/singles from package_booking_link to booking_link.

A colleague did git pull and got both changes from project config, resulting in the following error:

Status: Internal Server Error  
Respons: {"error":"SQLSTATE[23000]: Integrity constraint violation: 
1062 Duplicate entry 'booking_link-global' for key 'fields.fields_handle_context_unq_idx'
The SQL being executed was: 
UPDATE fields SET groupId=1, handle='booking_link', settings='{\\\"allowCustomText\\\":\\\"\\\",\\\"allowTarget\\\":\\\"\\\",\\\"allowedLinkNames\\\":{\\\"1\\\":\\\"entry\\\",\\\"8\\\":\\\"tel\\\",\\\"9\\\":\\\"url\\\"},\\\"autoNoReferrer\\\":\\\"\\\",\\\"defaultLinkName\\\":\\\"entry\\\",\\\"defaultText\\\":\\\"\\\",\\\"enableAriaLabel\\\":\\\"\\\",\\\"enableTitle\\\":\\\"\\\",\\\"typeSettings\\\":{\\\"entry\\\":{\\\"sources\\\":\\\"*\\\",\\\"allowCustomQuery\\\":\\\"\\\"},\\\"user\\\":{\\\"sources\\\":\\\"*\\\",\\\"allowCustomQuery\\\":\\\"\\\"},\\\"asset\\\":{\\\"sources\\\":\\\"*\\\",\\\"allowCustomQuery\\\":\\\"\\\"},\\\"category\\\":{\\\"sources\\\":\\\"*\\\",\\\"allowCustomQuery\\\":\\\"\\\"},\\\"site\\\":{\\\"sites\\\":\\\"*\\\"},\\\"custom\\\":{\\\"disableValidation\\\":\\\"\\\",\\\"allowAliases\\\":\\\"\\\"},\\\"email\\\":{\\\"disableValidation\\\":\\\"\\\",\\\"allowAliases\\\":\\\"\\\"},\\\"tel\\\":{\\\"disableValidation\\\":\\\"\\\",\\\"allowAliases\\\":\\\"\\\"},\\\"url\\\":{\\\"disableValidation\\\":\\\"\\\",\\\"allowAliases\\\":\\\"\\\"}}}', dateUpdated='2020-05-11 11:20:17' WHERE id=47"}

Workaround was to change handles between 2 syncs to all envs to avoid this error.

Craft 3.4.18
Typed link field 1.0.21

@nettum That sounds like a different bug. Can you post as a new GitHub issue please?

Of course, will try to replicate locally and post a new issue.

This is now fixed for the next 3.5 release.

@nettum sorry for the confusion… on further review I was wrong and this was the same bug as what you were reporting.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bitboxfw picture bitboxfw  Â·  3Comments

angrybrad picture angrybrad  Â·  3Comments

leigeber picture leigeber  Â·  3Comments

davist11 picture davist11  Â·  3Comments

richhayler picture richhayler  Â·  3Comments