[SOLVED] Save Error - Field Label don't exists

Hey guys, I am getting the following error in developer mode,

AttributeError: 'NoneType' object has no attribute 'label'

I have check my DocType, like a thousand times, and I have labell to all my Fields except the column breaks.

I even bench migrate thinking that it might be some older version of the DocType because my next logical assumption is that somewhere a Field I created and deleted, is kept.

Goes make sense to anyone? Anyone knows any tip or trick to debug this problem ?

Hi @kickapoo, please share full stack trace.

@Marcin_Walkow the Full track trace

Traceback (most recent call last):
  File "/Users/kickapoo/Dev/frappe-dev/frappe-bench/apps/frappe/frappe/desk/form/save.py", line 22, in savedocs
    doc.save()
  File "/Users/kickapoo/Dev/frappe-dev/frappe-bench/apps/frappe/frappe/model/document.py", line 242, in save
    return self._save(*args, **kwargs)
  File "/Users/kickapoo/Dev/frappe-dev/frappe-bench/apps/frappe/frappe/model/document.py", line 259, in _save
    self.insert()
  File "/Users/kickapoo/Dev/frappe-dev/frappe-bench/apps/frappe/frappe/model/document.py", line 207, in insert
    self.set_new_name()
  File "/Users/kickapoo/Dev/frappe-dev/frappe-bench/apps/frappe/frappe/model/document.py", line 325, in set_new_name
    set_new_name(self)
  File "/Users/kickapoo/Dev/frappe-dev/frappe-bench/apps/frappe/frappe/model/naming.py", line 45, in set_new_name
    frappe.throw(_("{0} is required").format(doc.meta.get_label(fieldname)))
  File "/Users/kickapoo/Dev/frappe-dev/frappe-bench/apps/frappe/frappe/model/meta.py", line 121, in get_label
    return self.get_field(fieldname).label
AttributeError: 'NoneType' object has no attribute 'label'

Traceback (most recent call last):
  File "/Users/kickapoo/Dev/frappe-dev/frappe-bench/apps/frappe/frappe/app.py", line 55, in application
    response = frappe.handler.handle()
  File "/Users/kickapoo/Dev/frappe-dev/frappe-bench/apps/frappe/frappe/handler.py", line 19, in handle
    execute_cmd(cmd)
  File "/Users/kickapoo/Dev/frappe-dev/frappe-bench/apps/frappe/frappe/handler.py", line 36, in execute_cmd
    ret = frappe.call(method, **frappe.form_dict)
  File "/Users/kickapoo/Dev/frappe-dev/frappe-bench/apps/frappe/frappe/__init__.py", line 879, in call
    return fn(*args, **newargs)
  File "/Users/kickapoo/Dev/frappe-dev/frappe-bench/apps/frappe/frappe/desk/form/save.py", line 22, in savedocs
    doc.save()
  File "/Users/kickapoo/Dev/frappe-dev/frappe-bench/apps/frappe/frappe/model/document.py", line 242, in save
    return self._save(*args, **kwargs)
  File "/Users/kickapoo/Dev/frappe-dev/frappe-bench/apps/frappe/frappe/model/document.py", line 259, in _save
    self.insert()
  File "/Users/kickapoo/Dev/frappe-dev/frappe-bench/apps/frappe/frappe/model/document.py", line 207, in insert
    self.set_new_name()
  File "/Users/kickapoo/Dev/frappe-dev/frappe-bench/apps/frappe/frappe/model/document.py", line 325, in set_new_name
    set_new_name(self)
  File "/Users/kickapoo/Dev/frappe-dev/frappe-bench/apps/frappe/frappe/model/naming.py", line 45, in set_new_name
    frappe.throw(_("{0} is required").format(doc.meta.get_label(fieldname)))
  File "/Users/kickapoo/Dev/frappe-dev/frappe-bench/apps/frappe/frappe/model/meta.py", line 121, in get_label
    return self.get_field(fieldname).label
AttributeError: 'NoneType' object has no attribute 'label'

Right now I am trying to debug in frappe/model/meta.py

@kickapoo, Might be label is missing in one of your fields. Refer following attachment -

Regards, Priya

@kickapoo:

Might be that you are using “name” as a field name which in my case sometimes created conflicts.
Frappe uses “name” in the DB instead of standard primary/foreign keys solution.

I would go for deleting doctype directories, removing doctype from GUI and then going for bench migrate.
Afterwards recreating doc.

@priya_s, Ty for answer but as I wrote, I have check my DocType, like a thousand times, and I have labels to all my Fields except the column breaks.

@Marcin_Walkow, I was suspecting the “name” issue and had already check. It not the case.

Deleting the DocType, I dont find this good idea because let’s think of the scenario that this error occurs then you make a change to huge production doctype.

@kickapoo

Right now you are developing & testing so let us spot the issue. Do not be concerned about the universal solutions for the future, focus on the ball :slight_smile:
For example I was trying to create doctype which contained name “Customer” and was unable to do so. After removing directories and cleaning stuff it worked.

For me it looks like there is a field in some place (in some list) which existed but right now it does not / or the labels were not set for particular fields. I would go to meta.py

And in function:

	def get_label(self, fieldname):
		return self.get_field(fieldname).label
	def get_label(self, fieldname):
	        print(fieldname)
                return self.get_field(fieldname).label

Not sure if print is gonna work (didn’t try it here yet), but when you have console up and running you should see each fieldname printed out.

@Marcin_Walkow, print didn’t work. Tried also to pass 'ipdb.set_trace()`

I will continue to search it…

@Marcin_Walkow and @priya_s, ty for your suggestions.

The solution was in front on me all the time,

the link @priya_s shared had it. The problem was that I had autoname using the deleted one

So for others:

Check your autofield settings in the DocType not to have ant deleted field name as input

Currently I am gathering some of the topics to work on the documentation - this is one of them.
Great it’s finally resolved.