Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions builder/builder/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,15 @@ def test_execute_script(self):
execute_script("data.sum = a + b", {"data": data, "a": 2, "b": 2}, "test.py")
self.assertEqual(data.sum, 4)

def test_execute_script_can_translate(self):
data = frappe._dict({})
execute_script('data.text = _("Supplier")', {"data": data}, "test.py")
self.assertEqual(data.text, "Supplier")

# the sandbox rejects `frappe._`, only the bare name works (#626)
with self.assertRaises(Exception):
execute_script('data.text = frappe._("Supplier")', {"data": data}, "test.py")

@patch("builder.utils.is_safe_exec_enabled", return_value=False)
@patch("frappe.utils.safe_exec.is_safe_exec_enabled", return_value=False)
def test_execute_script_with_enabled_server_script(self, *args):
Expand Down
2 changes: 2 additions & 0 deletions builder/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@ def get_safer_globals():
as_json=frappe.as_json,
dict=safe_globals["dict"],
args=form_dict,
# must stay top-level: safe_exec's _getattr_ guard rejects `frappe._`
_=frappe._,
frappe=NamespaceDict(
db=NamespaceDict(
count=frappe.db.count,
Expand Down
Loading