strapi-plugin-config-sync icon indicating copy to clipboard operation
strapi-plugin-config-sync copied to clipboard

Importing configs duplicates locales

Open samijuvaste-exove opened this issue 1 year ago • 7 comments

Bug report

Describe the bug

When there are at least three locales in config sync files and a single locale in database, importing configs will result in at least one duplicate locale in database. I couldn't reproduce the bug with sqlite database so this could have something to do with mysql.

Steps to reproduce the behavior

  1. Go to Internationalization settings in Strapi admin UI.
  2. Set at least three locales (any).
  3. Export config sync.
  4. Remove all but one locale.
  5. Import config sync.
  6. Now there is at least one duplicate locale in Internationalization settings. Duplicate rows can be found in i18n_locale database table too.

Expected behavior

There shouldn't be duplicate locales.

System

  • Node.js version: v20.17.0
  • NPM version: 10.8.2
  • Strapi version: 4.25.8
  • Plugin version: 1.2.6
  • Database: mysql (mysql2)

samijuvaste-exove avatar Aug 28 '24 10:08 samijuvaste-exove

Can confirm this issue with a Postgres DB as well.

boazpoolman avatar Aug 28 '24 13:08 boazpoolman

After some investigation I've figured out that there is actually an (unhandled) error occurring. Which is:

error: insert into "public"."admin_permissions" ("action", "action_parameters", "conditions", "created_at", "id", "properties", "subject", "updated_at") values ($1, $2, $3, $4, $5, $6, $7, $8) returning "id" - duplicate key value violates unique constraint "admin_permissions_pkey"
    at Parser.parseErrorMessage (/Users/boazpoolman/Code/boazpoolman/strapi/strapi-plugin-webtools/playground/node_modules/pg-protocol/dist/parser.js:283:98)
    at Parser.handlePacket (/Users/boazpoolman/Code/boazpoolman/strapi/strapi-plugin-webtools/playground/node_modules/pg-protocol/dist/parser.js:122:29)
    at Parser.parse (/Users/boazpoolman/Code/boazpoolman/strapi/strapi-plugin-webtools/playground/node_modules/pg-protocol/dist/parser.js:35:38)
    at Socket.<anonymous> (/Users/boazpoolman/Code/boazpoolman/strapi/strapi-plugin-webtools/playground/node_modules/pg-protocol/dist/index.js:11:42)
    at Socket.emit (node:events:514:28)
    at Socket.emit (node:domain:488:12)
    at addChunk (node:internal/streams/readable:376:12)
    at readableAddChunk (node:internal/streams/readable:349:9)
    at Readable.push (node:internal/streams/readable:286:10)
    at TCP.onStreamRead (node:internal/stream_base_commons:190:23) {
  length: 217,
  severity: 'ERROR',
  code: '23505',
  detail: 'Key (id)=(51) already exists.',
  hint: undefined,
  position: undefined,
  internalPosition: undefined,
  internalQuery: undefined,
  where: undefined,
  schema: 'public',
  table: 'admin_permissions',
  column: undefined,
  dataType: undefined,
  constraint: 'admin_permissions_pkey',
  file: 'nbtinsert.c',
  line: '666',
  routine: '_bt_check_unique'
}

Even though there is an error, the entry is still created, but a retry will happen because it thought the creation failed. Causing us to end up with two of the same entries. I'm investigating further.

boazpoolman avatar Aug 28 '24 14:08 boazpoolman

I've reported this as an issue to Strapi core https://github.com/strapi/strapi/issues/21100 as it can be reproduced outside the context of using this plugin

boazpoolman avatar Aug 28 '24 15:08 boazpoolman

Thanks a lot @boazpoolman . We were figuring also that this might be a core issue in Strapi.

ghost avatar Aug 29 '24 08:08 ghost

Now that Config Sync is fully supported on Strapi 5 with it's latest major release we could consider this issue fixed as it can't be reproduced in Strapi 5.

I'll leave the issue open with the label wontfix. In case anybody runs in to this issue in the future when still using Strapi 4.

boazpoolman avatar Oct 13 '24 09:10 boazpoolman

We have definitely seen this issue in all our environments (local, staging, production) when syncing configs.

Also the problem is very large because it causes data loss. Basically when you remove the duplicate language, Strapi deletes the content of the removed language even though there is still a second duplicate copy of the language still in the system.

Strapi v4 is supposed to be supported until March 2026 so it's a shame that the fix won't be made for Strapi v4.

ghost avatar Oct 13 '24 09:10 ghost

I completely understand where you’re coming from.

But this bug is not an issue with Config Sync, it’s an issue with Strapi core. And thus it can’t be fixed from within the Config Sync codebase. That is why I’ve labelled it wontfix in the repository.

Whether Strapi decides to fix this for Strapi 4 is not up to me. I would encourage you to voice your concern on the issue I’ve opened about this on the Strapi Github repo. Sadly there isn’t much more we can do.

boazpoolman avatar Oct 13 '24 10:10 boazpoolman

Seeing as Strapi closed the internal issue, and saying it will be unlikely they wil fix this for v4, I will go ahead and close this issue as well. After all, it’s just a side effect of a core issue of Strapi v4.

To solve the issue, please update to Strapi v5.

boazpoolman avatar Dec 29 '24 09:12 boazpoolman