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

Translation broken because of f-string use #26443

Closed
asharkinasuit opened this issue May 15, 2024 · 2 comments
Closed

Translation broken because of f-string use #26443

asharkinasuit opened this issue May 15, 2024 · 2 comments

Comments

@asharkinasuit
Copy link
Contributor

asharkinasuit commented May 15, 2024

Description of the issue

Translation is broken again because of continued usage of f-strings in at least one call to frappe._. This has been an issue in the past but I noticed the commit (557cb45) that introduces the bug was allowed to bypass CI, I wonder why.

If future versions support usage of f-strings in frappe._, backporting should still verify that it does not break older versions that do not.

Output of bench version

erpnext 14.45.0
frappe 14.74.1
hrms 14.14.0

Steps to reproduce the issue

  1. Go to the root of the Frappe installation (directory containing sites and apps)
  2. Run bench update-translations with suitable arguments for some language

Observed result

Translation fails to complete because of exception raised while trying to evaluate code from frappe/utils/jinja.py:69

Expected result

Translation completes without errors.

Stacktrace / full error message

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/local/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 109, in <module>
    main()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 18, in main
    click.Group(commands=commands)(prog_name="bench")
  File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/click/decorators.py", line 21, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/commands/__init__.py", line 29, in _func
    ret = f(frappe._dict(ctx.obj), *args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/commands/translate.py", line 77, in update_translations
    frappe.translate.update_translations(lang, untranslated_file, translated_file, app=app)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/translate.py", line 1110, in update_translations
    write_translations_file(app_name, lang, full_dict)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/translate.py", line 1183, in write_translations_file
    app_messages = get_messages_for_app(app)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/translate.py", line 427, in get_messages_for_app
    messages.extend(get_server_messages(app))
  File "/home/frappe/frappe-bench/apps/frappe/frappe/translate.py", line 657, in get_server_messages
    messages.extend(get_messages_from_file(os.path.join(basepath, f)))
  File "/home/frappe/frappe-bench/apps/frappe/frappe/translate.py", line 723, in get_messages_from_file
    messages += extract_messages_from_python_code(file_contents)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/translate.py", line 743, in extract_messages_from_python_code
    for message in extract_python(
  File "/home/frappe/frappe-bench/env/lib/python3.10/site-packages/babel/messages/extract.py", line 487, in extract_python
    value = eval(code, {'__builtins__': {}}, {})
  File "<string>", line 2, in <module>
NameError: name 'e' is not defined

Additional information

OS: Rocky Linux 9

ankush added a commit to ankush/frappe that referenced this issue May 16, 2024
@ankush ankush closed this as completed in afed21e May 17, 2024
mergify bot pushed a commit that referenced this issue May 17, 2024
closes #26443

(cherry picked from commit afed21e)
mergify bot pushed a commit that referenced this issue May 17, 2024
closes #26443

(cherry picked from commit afed21e)
ankush added a commit that referenced this issue May 17, 2024
* fix: dont translate syntax error messages

closes #26443

(cherry picked from commit afed21e)

* fix(DX): Don't run CI if there are no tests

New apps keep burning CI just to install the app and run nothing.
This adds a small check before install to avoid unnecessary CI runs.

(cherry picked from commit 1b0ad41)

---------

Co-authored-by: Ankush Menat <ankush@frappe.io>
ankush added a commit that referenced this issue May 17, 2024
* fix: dont translate syntax error messages

closes #26443

(cherry picked from commit afed21e)

* fix(DX): Don't run CI if there are no tests

New apps keep burning CI just to install the app and run nothing.
This adds a small check before install to avoid unnecessary CI runs.

(cherry picked from commit 1b0ad41)

---------

Co-authored-by: Ankush Menat <ankush@frappe.io>
@frappe-pr-bot
Copy link
Collaborator

🎉 This issue has been resolved in version 15.28.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@frappe-pr-bot
Copy link
Collaborator

🎉 This issue has been resolved in version 14.75.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants