pluginpal / strapi-plugin-config-sync

:recycle: CLI & GUI for continuous migration of config data across environments
https://www.pluginpal.io/plugin/config-sync
MIT License
250 stars 36 forks source link

Importing configs duplicates locales #133

Open samijuvaste-exove opened 2 weeks ago

samijuvaste-exove commented 2 weeks ago

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

boazpoolman commented 2 weeks ago

Can confirm this issue with a Postgres DB as well.

boazpoolman commented 2 weeks ago

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 commented 2 weeks ago

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

HeikkiYlipaavalniemi commented 2 weeks ago

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