Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Flask-BabelEx with Flask-Babel #2460

Merged
merged 5 commits into from
Jul 19, 2024
Merged

Replace Flask-BabelEx with Flask-Babel #2460

merged 5 commits into from
Jul 19, 2024

Conversation

samuelhwilliams
Copy link
Contributor

@samuelhwilliams samuelhwilliams commented Jul 16, 2024

Flask-BabelEx has been deprecated and archived. The original Flask-Babel is now alive and active again, so it makes sense to convert Flask-Admin back to using that library instead from v2.0.0.

Although Flask-Admin has claimed to support Flask-Babel at the same time as Flask-BabelEx, there was one semi-significant issue that I came across with only Flask-Babel: if the package is installed, but Flask-Babel is never initialised against the Flask app, then Flask-Admin will crash. Flask-BabelEx would silently fall back to the untranslated strings, but Flask-Admin does a hard lookup on app.extensions['babel'] and dies.

This led to a series of test changes in order to make sure that Flask-Babel is correctly set up for all tests. If Flask-Babel is not installed, this is a noop, which should also make it easier to run tests as a user that does not use Flask-Babel - something that does not currently happen, leaving a bit of a gap in our test coverage as flask_admin.babel has two very distinct code paths pivoted on whether the package is installed (note installed, not initialised against a Flask app)

closes: #2447

@samuelhwilliams samuelhwilliams marked this pull request as ready for review July 17, 2024 20:42
This allows us to have (almost) a single place where we have to think
about Babel (in the `babel`) fixture.

This should make it easier for us to, in the future, run tests without
babel or flask-babel installed, to validate flask-admin for users
without that package. This is important because the `flask_admin.babel`
module has two clearly different codepaths depending on whether the
package is installed.

Importantly, because of the fixture chaining (`admin` requires `babel`),
it also means that `babel` (if available) is always configured for every
flask app instance for every test.
Adds a `flask_babel` mark to any tests that explicitly require
`Flask-Babel` to be installed.

Configures tox and GitHub Actions to run a test suite with Flask-Babel
removed. This validates a codepath through `flask_admin.babel`, which
should essentially be passthrough/noop behaviour if Flask-Babel is
unavailable.
@samuelhwilliams samuelhwilliams merged commit 1b92bc7 into pallets-eco:master Jul 19, 2024
8 checks passed
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

Successfully merging this pull request may close these issues.

Remove Flask-BabelEx support?
1 participant