Skip to content

fix: import one config at a time, and exit 1 when a CLI import fails - #248

Open
marcelxpfeifer wants to merge 1 commit into
pluginpal:masterfrom
marcelxpfeifer:fix/import-one-config-at-a-time
Open

marcelxpfeifer wants to merge 1 commit into
pluginpal:masterfrom
marcelxpfeifer:fix/import-one-config-at-a-time

Conversation

@marcelxpfeifer

Copy link
Copy Markdown

What does it do?

  • config-sync import, importAllConfig (used by import on bootstrap) and the admin import endpoint import the configs one after the other instead of all at once with Promise.all. The first failure stops the rest.
  • config-sync import exits with code 1 when an import fails. It used to print the error and exit 0.

Exports stay parallel: each export writes only its own file from the database, so they don't affect each other.

Why is it needed?

Importing some configs changes others. Each new i18n locale makes Strapi rewrite the super admin's permissions, keeping their ids. On a new MariaDB database with several locale files, config-sync import -y failed on a random locale each run:

[error] Error: Error when trying to import i18n-locale.fr. Error: insert into `admin_permissions` ... - Duplicate entry '…' for key 'PRIMARY'

The command still exited 0, so a deploy or container start that runs config-sync import -y before strapi start carried on with half the config imported. This is the same race as #63, there through the admin panel's import.

How to test it?

On MySQL/MariaDB: create a few locales, export, drop the database, then run config-sync import -y. Before this change it fails on one of the locales (not on every run) and exits 0. With it, every locale is imported.

On SQLite the race doesn't happen (better-sqlite3 answers synchronously, so one import finishes before the next one starts). The new tests therefore count overlapping imports:

  • playground/__tests__/import.test.js: imports three locales with importAllConfig and three through the admin import endpoint, and checks that no two imports run at the same time.
  • cli.test.js: a partial import whose first config is an invalid file exits 1 and leaves the next config alone.

Ran yarn eslint and yarn test:integration locally (Node 26, SQLite): all pass. On master the three new tests fail. I didn't run the Cypress e2e tests.

Risk: a large import takes longer, because configs no longer import in parallel. Scripts that relied on config-sync import exiting 0 after a failed import now stop.

How to revert: revert the commit. Nothing is stored differently.

Related issue(s)/PR(s)

#63

The CLI, importAllConfig (import on bootstrap) and the admin import endpoint
imported every config at once. Importing some configs changes others: each
new i18n locale makes Strapi rewrite the super admin's permissions, so on
MySQL/MariaDB two locales imported together could fail with a duplicate
admin_permissions id. The imports now run one after the other, and the
first failure stops the rest.

`config-sync import` printed the error and still exited 0, so a deploy that
runs it carried on with half-imported config. It now exits 1.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant