Repository navigation
fix: import one config at a time, and exit 1 when a CLI import fails - #248
Open
marcelxpfeifer wants to merge 1 commit into
Open
marcelxpfeifer wants to merge 1 commit into
marcelxpfeifer wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 withPromise.all. The first failure stops the rest.config-sync importexits 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 -yfailed on a random locale each run:The command still exited 0, so a deploy or container start that runs
config-sync import -ybeforestrapi startcarried 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 withimportAllConfigand 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 eslintandyarn test:integrationlocally (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 importexiting 0 after a failed import now stop.How to revert: revert the commit. Nothing is stored differently.
Related issue(s)/PR(s)
#63