Try ERPNext Buy Support Partners Foundation

Have you ever seen:: " NameError: name '_print_' is not defined"?

I have been working on a custom app for weeks now, due to some quite complex validation conditions.

Now, finally, with my tests seemingly complete I find it impossible to submit the prepared form.

/home/erpdev/frappe-bench-DYPW/env/lib/python3.8/site-packages/RestrictedPython/compile.py:209: 
  SyntaxWarning: Line None: Prints, but never reads 'printed' variable.
  warnings.warn(
Traceback (most recent call last):
  File "/home/erpdev/frappe-bench-DYPW/apps/frappe/frappe/desk/form/save.py", line 19, in savedocs
    doc.submit()
  File "/home/erpdev/frappe-bench-DYPW/apps/frappe/frappe/model/document.py", line 897, in submit
    self._submit()
  File "/home/erpdev/frappe-bench-DYPW/apps/frappe/frappe/model/document.py", line 886, in _submit
    self.save()
  File "/home/erpdev/frappe-bench-DYPW/apps/frappe/frappe/model/document.py", line 281, in save
    return self._save(*args, **kwargs)
  File "/home/erpdev/frappe-bench-DYPW/apps/frappe/frappe/model/document.py", line 316, in _save
    self.run_before_save_methods()
  File "/home/erpdev/frappe-bench-DYPW/apps/frappe/frappe/model/document.py", line 931, in run_before_save_methods
    self.run_method("before_submit")
  File "/home/erpdev/frappe-bench-DYPW/apps/frappe/frappe/model/document.py", line 831, in run_method
    run_server_script_for_doc_event(self, method)
File "/home/erpdev/frappe-bench-DYPW/apps/frappe/frappe/core/doctype/server_script/server_script_utils.py", line 43, in run_server_script_for_doc_event
    frappe.get_doc('Server Script', script_name).execute_doc(doc)
  File "/home/erpdev/frappe-bench-DYPW/apps/frappe/frappe/core/doctype/server_script/server_script.py", line 34, in execute_doc
    safe_exec(self.script, None, dict(doc = doc))
  File "/home/erpdev/frappe-bench-DYPW/apps/frappe/frappe/utils/safe_exec.py", line 29, in safe_exec
    exec(compile_restricted(script), exec_globals, _locals) # pylint: disable=exec-used
  File "<unknown>", line 1, in <module>
NameError: name '_print_' is not defined

( I broke it into sections so you don’t have to scroll )

What am I to make of :: “SyntaxWarning: Line None: Prints, but never reads ‘printed’ variable” ???

To begin to track down the problem I reverted to the original placeholder code…

# -*- coding: utf-8 -*-
# Copyright (c) 2020, Warehouseman and contributors
# For license information, please see license.txt

from __future__ import unicode_literals
# import frappe
from frappe.model.document import Document

class ReturnableBatch(Document):
  pass

YET THE ERROR STILL OCCURS???

If this rings any bells with you please let me know.

I figured this out at last.

I was trying to get started with Server Scripts and got interrupted by a minor emergency – then completely forgot about ever starting it all. :grimacing:

Presumably this is self-explanatory:

It turns out that using Python print is illegal in a Server Script

The only legal commands are listed in the documentation in Customize ERPNext / Server Script :: 2.3 Security

As you can see I was attempting to create a Server Script “Hello World”, but that deserves a separate post: Does there exist a “Hello World” example for a Server Script.