Meaning of "object has no attribute" Error

Hi all,

I would ask about these error, which appears many time :
AttributeError:’ --------’ object has no attribute

My case is:
when i define a function in .py file and then call it in .js file, that error appear although the attribute he asked about is existed but he can not see it

any explanation plz??

Hi @MaysaaSafadi

Can you share the code

Here the message:
Traceback (most recent call last):
File “/home/frappe/frappe-bench/apps/frappe/frappe/”, line 55, in application
response = frappe.handler.handle()
File “/home/frappe/frappe-bench/apps/frappe/frappe/”, line 19, in handle
File “/home/frappe/frappe-bench/apps/frappe/frappe/”, line 40, in execute_cmd
ret =, **frappe.form_dict)
File “/home/frappe/frappe-bench/apps/frappe/frappe/”, line 896, in call
return fn(*args, **newargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/”, line 71, in runserverobj
frappe.desk.form.run_method.runserverobj(method, docs=docs, dt=dt, dn=dn, arg=arg, args=args)
File “/home/frappe/frappe-bench/apps/frappe/frappe/desk/form/”, line 33, in runserverobj
fnargs, varargs, varkw, defaults = inspect.getargspec(getattr(doc, method))
AttributeError: ‘ServiceRequest’ object has no attribute ‘generate_auto_request_num’

Hi @MaysaaSafadi

Can you share your custom code?
It seems that, the py method is not called from the JS properly

Thank u for your reply @rohit_w

I called it and it work fine on my local but when i run it on server , the problem appaer
Here the function on .py file

def generate_auto_request_num (self):
d =
auto_num =self.generat_auto_num()
self.request_number = str(d.year) + str(d.month) +‘0000’+ str(auto_num)
self.auto_num = auto_num
return self.request_number

and in the .js file:
onload: function(frm) {

@rohit_w here the rest of the code, sorry of that trubble,

var generate_auto_request_num = function (doc) {
** doc: doc,**
** method: “generate_auto_request_num”,**
** callback: function (r) {**
** // console.log(r)**
** refresh_many([“request_number”]);**
** }**

@MaysaaSafadi you need to whitelist the function:

def generate_auto_request_num(self): 

in order to call from JS

@JoEz but the tow files are in the same place, the .py and the .js also

@MaysaaSafadi what u mean “are in the same place?”. In order to call a python method from js u need to whitelist

Hi @MaysaaSafadi

You need to pass the object(frm.doc) in the json{
  doc: frm.doc,
  method: generate_auto_request_num,
  callback: function(r, rt) {
     //call back operation

for example see below code
JS Code

PY code

1 Like