Skip to content

[SQL Lab] Cannot perform any query when change language #27367

Closed

Description

@guilhermefacanha

Bug description

I'm using version 3.1.1

image

When I have superset configured in English, I can load tables, preview, and execute SQL without problems

image

When I switch to Portuguese language, I start getting not enough arguments for format string error in preview or any sql execution

Log

2024-03-02 00:39:11 Query 75: Executing 1 statement(s)
2024-03-02 00:39:11 2024-03-02 08:39:11,948:INFO:superset.sql_lab:Query 75: Executing 1 statement(s)
2024-03-02 00:39:11 Query 75: Set query to 'running'
2024-03-02 00:39:11 2024-03-02 08:39:11,948:INFO:superset.sql_lab:Query 75: Set query to 'running'
2024-03-02 00:39:12 SupersetErrorsException
2024-03-02 00:39:12 Traceback (most recent call last):
2024-03-02 00:39:12   File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1823, in full_dispatch_request
2024-03-02 00:39:12     rv = self.dispatch_request()
2024-03-02 00:39:12   File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1799, in dispatch_request
2024-03-02 00:39:12     return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
2024-03-02 00:39:12   File "/app/superset_home/.local/lib/python3.9/site-packages/flask_appbuilder/security/decorators.py", line 95, in wraps
2024-03-02 00:39:12     return f(self, *args, **kwargs)
2024-03-02 00:39:12   File "/app/superset_home/.local/lib/python3.9/site-packages/superset/views/base_api.py", line 127, in wraps
2024-03-02 00:39:12     raise ex
2024-03-02 00:39:12   File "/app/superset_home/.local/lib/python3.9/site-packages/superset/views/base_api.py", line 121, in wraps
2024-03-02 00:39:12     duration, response = time_function(f, self, *args, **kwargs)
2024-03-02 00:39:12   File "/app/superset_home/.local/lib/python3.9/site-packages/superset/utils/core.py", line 1463, in time_function
2024-03-02 00:39:12     response = func(*args, **kwargs)
2024-03-02 00:39:12   File "/app/superset_home/.local/lib/python3.9/site-packages/superset/views/base_api.py", line 93, in wraps
2024-03-02 00:39:12     return f(self, *args, **kwargs)
2024-03-02 00:39:12   File "/app/superset_home/.local/lib/python3.9/site-packages/superset/utils/log.py", line 255, in wrapper
2024-03-02 00:39:12     value = f(*args, **kwargs)
2024-03-02 00:39:12   File "/app/superset_home/.local/lib/python3.9/site-packages/superset/sqllab/api.py", line 407, in execute_sql_query
2024-03-02 00:39:12     command_result: CommandResult = command.run()
2024-03-02 00:39:12   File "/app/superset_home/.local/lib/python3.9/site-packages/superset/commands/sql_lab/execute.py", line 121, in run
2024-03-02 00:39:12     raise ex
2024-03-02 00:39:12   File "/app/superset_home/.local/lib/python3.9/site-packages/superset/commands/sql_lab/execute.py", line 103, in run
2024-03-02 00:39:12     status = self._run_sql_json_exec_from_scratch()
2024-03-02 00:39:12   File "/app/superset_home/.local/lib/python3.9/site-packages/superset/commands/sql_lab/execute.py", line 161, in _run_sql_json_exec_from_scratch
2024-03-02 00:39:12     raise ex
2024-03-02 00:39:12   File "/app/superset_home/.local/lib/python3.9/site-packages/superset/commands/sql_lab/execute.py", line 156, in _run_sql_json_exec_from_scratch
2024-03-02 00:39:12     return self._sql_json_executor.execute(
2024-03-02 00:39:12   File "/app/superset_home/.local/lib/python3.9/site-packages/superset/sqllab/sql_json_executer.py", line 111, in execute
2024-03-02 00:39:12     raise SupersetErrorsException(
2024-03-02 00:39:12 superset.exceptions.SupersetErrorsException: [SupersetError(message='not enough arguments for format string', error_type=<SupersetErrorType.GENERIC_DB_ENGINE_ERROR: 'GENERIC_DB_ENGINE_ERROR'>, level=<ErrorLevel.ERROR: 'error'>, extra={'engine_name': 'PostgreSQL', 'issue_codes': [{'code': 1002, 'message': 'Issue 1002 - O banco de dados retornou um erro inesperado.'}]})]
2024-03-02 00:39:12 2024-03-02 08:39:12,063:WARNING:superset.views.base:SupersetErrorsException
2024-03-02 00:39:12 Traceback (most recent call last):
2024-03-02 00:39:12   File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1823, in full_dispatch_request
2024-03-02 00:39:12     rv = self.dispatch_request()
2024-03-02 00:39:12   File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1799, in dispatch_request
2024-03-02 00:39:12     return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
2024-03-02 00:39:12   File "/app/superset_home/.local/lib/python3.9/site-packages/flask_appbuilder/security/decorators.py", line 95, in wraps
2024-03-02 00:39:12     return f(self, *args, **kwargs)
2024-03-02 00:39:12   File "/app/superset_home/.local/lib/python3.9/site-packages/superset/views/base_api.py", line 127, in wraps
2024-03-02 00:39:12     raise ex
2024-03-02 00:39:12   File "/app/superset_home/.local/lib/python3.9/site-packages/superset/views/base_api.py", line 121, in wraps
2024-03-02 00:39:12     duration, response = time_function(f, self, *args, **kwargs)
2024-03-02 00:39:12   File "/app/superset_home/.local/lib/python3.9/site-packages/superset/utils/core.py", line 1463, in time_function
2024-03-02 00:39:12     response = func(*args, **kwargs)
2024-03-02 00:39:12   File "/app/superset_home/.local/lib/python3.9/site-packages/superset/views/base_api.py", line 93, in wraps
2024-03-02 00:39:12     return f(self, *args, **kwargs)
2024-03-02 00:39:12   File "/app/superset_home/.local/lib/python3.9/site-packages/superset/utils/log.py", line 255, in wrapper
2024-03-02 00:39:12     value = f(*args, **kwargs)
2024-03-02 00:39:12   File "/app/superset_home/.local/lib/python3.9/site-packages/superset/sqllab/api.py", line 407, in execute_sql_query
2024-03-02 00:39:12     command_result: CommandResult = command.run()
2024-03-02 00:39:12   File "/app/superset_home/.local/lib/python3.9/site-packages/superset/commands/sql_lab/execute.py", line 121, in run
2024-03-02 00:39:12     raise ex
2024-03-02 00:39:12   File "/app/superset_home/.local/lib/python3.9/site-packages/superset/commands/sql_lab/execute.py", line 103, in run
2024-03-02 00:39:12     status = self._run_sql_json_exec_from_scratch()
2024-03-02 00:39:12   File "/app/superset_home/.local/lib/python3.9/site-packages/superset/commands/sql_lab/execute.py", line 161, in _run_sql_json_exec_from_scratch
2024-03-02 00:39:12     raise ex
2024-03-02 00:39:12   File "/app/superset_home/.local/lib/python3.9/site-packages/superset/commands/sql_lab/execute.py", line 156, in _run_sql_json_exec_from_scratch
2024-03-02 00:39:12     return self._sql_json_executor.execute(
2024-03-02 00:39:12   File "/app/superset_home/.local/lib/python3.9/site-packages/superset/sqllab/sql_json_executer.py", line 111, in execute
2024-03-02 00:39:12     raise SupersetErrorsException(
2024-03-02 00:39:12 superset.exceptions.SupersetErrorsException: [SupersetError(message='not enough arguments for format string', error_type=<SupersetErrorType.GENERIC_DB_ENGINE_ERROR: 'GENERIC_DB_ENGINE_ERROR'>, level=<ErrorLevel.ERROR: 'error'>, extra={'engine_name': 'PostgreSQL', 'issue_codes': [{'code': 1002, 'message': 'Issue 1002 - O banco de dados retornou um erro inesperado.'}]})]

How to reproduce the bug

  1. Go to SQL Lab
  2. Make sure you can preview or execute SQL statement
  3. Change Language, I used Portuguese BR
  4. Reload page
  5. Neither preview or SQL execution works

Screenshots/recordings

No response

Superset version

3.1.1

Python version

3.9

Node version

I don't know

Browser

Firefox

Additional context

No response

Checklist

  • I have searched Superset docs and Slack and didn't find a solution to my problem.
  • I have searched the GitHub issue tracker and didn't find a similar bug report.
  • I have checked Superset's logs for errors and if I found a relevant Python stacktrace, I included it here as text in the "additional context" section.

Activity

  1. davidkestering commented on Apr 21, 2024

    @davidkestering

    The same issue happens with me too! I am running version 4.0.0

  2. desennalin commented on Jul 3, 2024

    @desennalin

    Same problem here in version 4, I had to switch back to English, do you want anything?

  3. rusackas commented on Jul 3, 2024

    @rusackas
    Member
  4. dosubot commented on Jul 3, 2024

    @dosubot

    Hello, @rusackas! I'm here to help you with any issues you may have while waiting for a human maintainer. I can help you solve bugs, answer questions, and become a contributor. Let me know how I can assist you!

    To resolve the "not enough arguments for format string" error in Apache Superset when switching the language to Portuguese (BR) and attempting to preview or execute SQL statements, you need to ensure that the translation strings in the messages.po file correctly match the placeholders used in the original English strings.

    For example, there is a mismatch in the translation for the following message:

    #: superset/commands/database/validate_sql.py:74
    #, python-format
    msgid ""
    "%(validator)s was unable to check your query.\n"
    "Please recheck your query.\n"
    "Exception: %(ex)s"
    msgstr ""
    "%(validador)es não conseguiu verificar sua consulta.\n"
    "Por favor revise sua consulta.\n"
    "Exceção: %(ex)s"

    The placeholder %(validator)s in the original message is incorrectly translated as %(validador)es in the Portuguese message. The correct translation should maintain the same placeholder names:

    msgstr ""
    "%(validator)s não conseguiu verificar sua consulta.\n"
    "Por favor revise sua consulta.\n"
    "Exceção: %(ex)s"

    Ensure that all placeholders in the translated strings match the original placeholders exactly. This should resolve the "not enough arguments for format string" error [1].

    To continue talking to Dosu, mention @dosu.

  5. lulrich commented on Nov 5, 2024

    @lulrich

    I don't know if they've already solved this problem or not, but I fixed it by changing these translations here

    #: superset/sql_lab.py:480
    #, python-format
    msgid "Running statement %(statement_num)s out of %(statement_count)s"
    msgstr "Executando instrução %(statement_num)s de % (statement_count)s"
    
    #: superset/sql_lab.py:503
    #, python-format
    msgid "Statement %(statement_num)s out of %(statement_count)s"
    msgstr "Instrução %(statement_ num)s de % (statement_count)s"

    deleting the space between % and (

    #: superset/sql_lab.py:480
    #, python-format
    msgid "Running statement %(statement_num)s out of %(statement_count)s"
    msgstr "Executando instrução %(statement_num)s de %(statement_count)s"
    
    #: superset/sql_lab.py:503
    #, python-format
    msgid "Statement %(statement_num)s out of %(statement_count)s"
    msgstr "Instrução %(statement_num)s de %(statement_count)s"

    and I've also changed these here

    #: superset/sql_lab.py:503
    #, python-format
    msgid "Statement %(statement_num)s out of %(statement_count)s"
    msgstr "Instrução %(statement_ num)s de %(statement_count)s"
    
    #: superset/jinja_context.py:353
    #, python-format
    msgid "Unsafe return type for function %(func)s: %(value_type)s"
    msgstr "Tipo de retorno inseguro para a função %(func)s: %(value_ type)s"
    
    #: superset/jinja_context.py:380
    #, python-format
    msgid "Unsafe template value for key %(key)s: %(value_type)s"
    msgstr "Valor de modelo não seguro para a chave %(key)s: %(value_ type)s"
    
    #: superset-frontend/plugins/plugin-chart-table/src/TableChart.tsx:198
    msgid "page_size.entries"
    msgstr "page_ size.entries"
    
    #: superset-frontend/plugins/plugin-chart-table/src/TableChart.tsx:178
    msgid "page_size.show"
    msgstr "page_ size.show"

    removing the space after _

    #: superset/sql_lab.py:503
    #, python-format
    msgid "Statement %(statement_num)s out of %(statement_count)s"
    msgstr "Instrução %(statement_ num)s de %(statement_count)s"
    
    #: superset/jinja_context.py:353
    #, python-format
    msgid "Unsafe return type for function %(func)s: %(value_type)s"
    msgstr "Tipo de retorno inseguro para a função %(func)s: %(value_ type)s"
    
    #: superset/jinja_context.py:380
    #, python-format
    msgid "Unsafe template value for key %(key)s: %(value_type)s"
    msgstr "Valor de modelo não seguro para a chave %(key)s: %(value_type)s"
    
    #: superset-frontend/plugins/plugin-chart-table/src/TableChart.tsx:198
    msgid "page_size.entries"
    msgstr "page_size.entries"
    
    #: superset-frontend/plugins/plugin-chart-table/src/TableChart.tsx:178
    msgid "page_size.show"
    msgstr "page_size.show"
  6. rusackas commented on Apr 21, 2025

    @rusackas
    Member

    I don't see % ( (with the space) in the current codebase, so I'll assume this is resolved, and that's why it's been silent here for upward of 6 months. Holler if this needs to be reopened for whatever reason!

  7. vit-opti commented on Apr 22, 2026

    @vit-opti

    Still present in version 6.0.0 with the French translation.

    The string "Running block %(block_num)s out of %(block_count)s" in sql_lab.py is translated in translations/fr/LC_MESSAGES/messages.json as:

    "Exécution de l'instruction %(statement_num)s sur %(statement_count)s"
    

    The variables %(block_num)s and %(block_count)s are replaced by %(statement_num)s and %(statement_count)s, which do not exist in the format call, causing a KeyError('statement_num') that propagates as a SupersetErrorsException and makes every SQL Lab query fail — including SELECT 1.

    Workaround: add BABEL_DEFAULT_LOCALE = "en" in superset_config.py.

    The fix would be to correct the French translation to use the right variable names:

    "Exécution du bloc %(block_num)s sur %(block_count)s"
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions