System Console for frappe.db.get_value error name '_unpack_sequence_' is not defined

Hello,

What wrong I am doing?

ref_doctype, ref_docname = frappe.db.get_value('Additional Salary', 'HR-ADS-24-02-00181', ['ref_doctype', 'ref_docname'])
log(ref_docname )

Error :

Traceback (most recent call last):
  File "apps/frappe/frappe/desk/doctype/system_console/system_console.py", line 32, in run
    safe_exec(self.console, script_filename="System Console")
  File "apps/frappe/frappe/utils/safe_exec.py", line 100, in safe_exec
    exec(
  File "<serverscript>: system_console", line 1, in <module>
NameError: name '_unpack_sequence_' is not defined

Reference : Database API

But When I am trying as below.

values = frappe.db.get_value('Additional Salary', 'HR-ADS-24-02-00181', ['ref_doctype', 'ref_docname'], as_dict=1)
log(values.ref_docname)

Result : (working fine)

LOAN-2024-00033

You’re not doing anything wrong. Certain operations are restricted in safe_exec, one of them is unpacking values.

Alternate:

  • Get two values one at a time
  • Use returned list to index into and set two of them separately.

We can possibly allow this operation, but requires a security review.

https://restrictedpython.readthedocs.io/en/latest/usage/policy.html#guards

2 Likes

Thanks @ankush