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

fix: remove global _("translation") calls #32828

Merged
merged 2 commits into from
Nov 5, 2022
Merged

Conversation

ankush
Copy link
Member

@ankush ankush commented Nov 2, 2022

This is not how it works. Translations are dynamic based on language
set during request (using header, user's preferences etc)

Calling them on global variables makes no sense.

Ref: frappe/frappe#18733

This is not how it works. Translations are dynamic based on language
sets during request (using header, user's preferences etc)

Calling them on global variables makes no sense.

Ref: frappe/frappe#18733
@github-actions github-actions bot added the needs-tests This PR needs automated unit-tests. label Nov 2, 2022
@ankush ankush removed the needs-tests This PR needs automated unit-tests. label Nov 2, 2022
@ankush ankush merged commit 75983ce into frappe:develop Nov 5, 2022
@barredterra barredterra added the backport version-14-hotfix backport to version 14 label Jan 9, 2024
mergify bot pushed a commit that referenced this pull request Jan 9, 2024
This is not how it works. Translations are dynamic based on language
sets during request (using header, user's preferences etc)

Calling them on global variables makes no sense.

Ref: frappe/frappe#18733
(cherry picked from commit 75983ce)
@barredterra
Copy link
Collaborator

barredterra commented Jan 9, 2024

bench version does not work in v14 due to circular imports caused by using the translation function in hooks.py. Let's backport this.

Details
> bench version

Traceback (most recent call last):
  File "/python/3.10/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/python/3.10/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 109, in <module>
    main()
  File "frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 18, in main
    click.Group(commands=commands)(prog_name="bench")
  File "frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "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 "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 "frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "frappe-bench/env/lib/python3.10/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "frappe-bench/apps/frappe/frappe/commands/utils.py", line 1098, in get_version
    app_hooks = frappe.get_module(app + ".hooks")
  File "frappe-bench/apps/frappe/frappe/__init__.py", line 1340, in get_module
    return importlib.import_module(modulename)
  File "/python/3.10/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "frappe-bench/apps/erpnext/erpnext/hooks.py", line 95, in <module>
    "defaults": {"doctype": "Sales Order", "parents": [{"label": _("Orders"), "route": "orders"}]},
  File "frappe-bench/apps/frappe/frappe/__init__.py", line 95, in _
    from frappe.translate import get_all_translations
  File "frappe-bench/apps/frappe/frappe/translate.py", line 25, in <module>
    from frappe.model.utils import InvalidIncludePath, render_include
  File "frappe-bench/apps/frappe/frappe/model/__init__.py", line 137, in <module>
    {"fieldname": "name", "fieldtype": "Link", "label": _("ID")},
  File "frappe-bench/apps/frappe/frappe/__init__.py", line 95, in _
    from frappe.translate import get_all_translations
ImportError: cannot import name 'get_all_translations' from partially initialized module 'frappe.translate' (most likely due to a circular import) (frappe-bench/apps/frappe/frappe/translate.py)

@ankush ankush deleted the no_translate branch January 9, 2024 04:56
ankush added a commit that referenced this pull request Jan 10, 2024
fix: remove global _("translation") calls (#32828)

This is not how it works. Translations are dynamic based on language
sets during request (using header, user's preferences etc)

Calling them on global variables makes no sense.

Ref: frappe/frappe#18733
(cherry picked from commit 75983ce)

Co-authored-by: Ankush Menat <ankush@frappe.io>
frappe-pr-bot pushed a commit that referenced this pull request Jan 10, 2024
# [14.59.0](v14.58.1...v14.59.0) (2024-01-10)

### Bug Fixes

* add read permission to Buying Settings (backport [#39158](#39158)) ([#39257](#39257)) ([a15ad80](a15ad80))
* asset WDV depreciation calc according to IT act ([1cbe1e8](1cbe1e8))
* BOM replace tool does not update exploded items of root (backport [#39244](#39244)) ([#39249](#39249)) ([c2eeeec](c2eeeec))
* don't set rate for non-stock item in Internal Transfer (backport [#39140](#39140)) ([#39168](#39168)) ([06d193a](06d193a))
* Duplicate Closing Stock Balance (backport [#39262](#39262)) ([#39263](#39263)) ([a3146c3](a3146c3))
* **Employee:** treeview ([#39126](#39126)) ([080a742](080a742))
* FG Item incorrect qty in the work order (backport [#39200](#39200)) ([#39210](#39210)) ([5e517cf](5e517cf))
* Ignore asset qty and status validation while cancelling LCV ([952cee3](952cee3))
* Ignore UP on "allowed to transact with" (backport [#39103](#39103)) ([#39104](#39104)) ([7d64df0](7d64df0))
* improved validation message ([580e9f6](580e9f6))
* incorrect indicator title for portal sales order (backport [#39247](#39247)) ([#39254](#39254)) ([8c496fb](8c496fb))
* inventory dimension negative stock validation (backport [#39149](#39149)) ([#39150](#39150)) ([2866f7c](2866f7c))
* possible typeerror on transaction.js ([8fe346a](8fe346a))
* Purchase date and amount is not mandatory for composite asset creation ([0f6477a](0f6477a))
* remove global _("translation") calls (backport [#32828](#32828)) ([#39231](#39231)) ([ee7474b](ee7474b))
* resolved conflict ([b529883](b529883))
* set `First Name` in Supplier Contact ([69c460c](69c460c))
* Set asset purchase amount based on qty and valuation_rate ([41e3843](41e3843))
* set parent doctype on chart (backport [#39286](#39286)) ([#39287](#39287)) ([a2a8558](a2a8558))
* Show maintain-stock and is-fixed-asset checkbox in item quick entry dialog ([7b4b630](7b4b630))
* Show timesheet table after fetching data from timesheet (backport [#39275](#39275)) ([#39280](#39280)) ([1cc887a](1cc887a))
* skip rate validation for return `DN Items` with `Moving Average` valuation (backport [#39242](#39242)) ([#39265](#39265)) ([f42e93b](f42e93b))
* total allocated percentage for sales team issue ([71f9b7f](71f9b7f))
* TypeError is pricing rules (backport [#39252](#39252)) ([#39259](#39259)) ([36ba33c](36ba33c))
* typerror on multi select dialog ([71ecf08](71ecf08))
* update Maintenance Schedule status on Maintenance Visit submit (backport [#39167](#39167)) ([#39185](#39185)) ([2ea2146](2ea2146))
* **UX:** dont override framework's permission check messages (backport [#39118](#39118)) ([#39119](#39119)) ([26ae708](26ae708))

### Features

* Copy project_name, from_time, to_time from timesheet details to sales invoice ([#33726](#33726)) ([d0e1162](d0e1162))
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
backport version-14-hotfix backport to version 14
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants