lironsam opened a new issue, #38468:
URL: https://github.com/apache/superset/issues/38468

   ## Bug Description
   
   SQL Lab queries fail with a `KeyError` when `BABEL_DEFAULT_LOCALE` is set to 
`"fr"` (French). Any SQL query execution in SQL Lab crashes during the progress 
message translation.
   
   ## Root Cause
   
   In a recent refactor, the variables in `sql_lab.py` were renamed from 
`statement_num`/`statement_count` to `block_num`/`block_count`:
   
   ```python
   # Current code in superset/sql_lab.py (~line 478):
   msg = __(
       "Running block %(block_num)s out of %(block_count)s",
       block_num=i + 1,
       block_count=len(blocks),
   )
   ```
   
   However, the **French translation** (`.po`/`.mo` files) still references the 
**old** variable names:
   
   ```po
   # In superset/translations/fr/LC_MESSAGES/messages.po:
   msgid "Running statement %(statement_num)s out of %(statement_count)s"
   msgstr "Exécution de l'instruction %(statement_num)s sur %(statement_count)s"
   ```
   
   When `flask_babel.gettext` performs `translated_string % variables`, Python 
raises a `KeyError` because the French translated string contains 
`%(statement_num)s` but the code passes `block_num` as the keyword argument.
   
   ## Steps to Reproduce
   
   1. Install Apache Superset 6.0.0
   2. Set `BABEL_DEFAULT_LOCALE = "fr"` in `superset_config.py`
   3. Configure `LANGUAGES` to include French:
      ```python
      LANGUAGES = {
          "fr": {"flag": "fr", "name": "French"},
          "en": {"flag": "us", "name": "English"},
      }
      ```
   4. Open SQL Lab
   5. Execute any SQL query
   
   ## Error
   
   ```
   KeyError: 'statement_num'
   ```
   
   The error occurs in `superset/sql_lab.py` when the `__()` (gettext) call 
tries to interpolate the translated French string with the new variable names 
(`block_num`/`block_count`), but the French `.mo` file's translated string 
still expects the old names (`statement_num`/`statement_count`).
   
   ## Expected Behavior
   
   SQL Lab queries should execute successfully regardless of the configured 
locale.
   
   ## Superset Version
   
   - **Version**: 6.0.0
   - **Python**: 3.11
   - **Deployment**: pip install
   
   ## Suggested Fix
   
   Update the French `.po` file to use the new variable names:
   
   ```po
   msgid "Running block %(block_num)s out of %(block_count)s"
   msgstr "Exécution du bloc %(block_num)s sur %(block_count)s"
   ```
   
   Then recompile the `.mo` file. This should also be checked for **all other 
language translation files** that may still reference 
`statement_num`/`statement_count`.
   
   ## Workaround
   
   Either:
   1. Set `BABEL_DEFAULT_LOCALE = "en"` to avoid French translations
   2. Patch the installed `sql_lab.py` to revert the variable names:
      ```bash
      sed -i 's/block_num/statement_num/g; s/block_count/statement_count/g' \
        $(python -c "import superset; print(superset.__path__[0])")/sql_lab.py
      ```
   
   ## Related Issues
   
   - #27367 — Similar issue for Portuguese (malformed placeholders). That issue 
was about **spaces breaking `%(...)s` syntax**. This issue is about **stale 
variable names after a code rename** not reflected in translation files.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to