Error on "bench reload-doctype Domain"

  • Debian 9.x
    • bench v. 4.1.0
    • Frappe 10.1.45
    • ERP Next 10.1.48

During an update, I had an error indicating missing/damaged doctype, so I used

bench reload-doctype Event
bench reload-doctype Domain

(the second of) which resulted in this … any pointers (please) :blush:?

      File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
        "__main__", fname, loader, pkg_name)
      File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
        exec code in run_globals
      File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 94, in <module>
        main()
      File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 18, in main
        click.Group(commands=commands)(prog_name='bench')
      File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 722, in __call__
        return self.main(*args, **kwargs)
      File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 697, in main
        rv = self.invoke(ctx)
      File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 1066, in invoke
        return _process_result(sub_ctx.command.invoke(sub_ctx))
      File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 1066, in invoke
        return _process_result(sub_ctx.command.invoke(sub_ctx))
      File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 895, in invoke
        return ctx.invoke(self.callback, **ctx.params)
      File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 535, in invoke
        return callback(*args, **kwargs)
      File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/decorators.py", line 17, in new_func
        return f(get_current_context(), *args, **kwargs)
      File "/home/frappe/frappe-bench/apps/frappe/frappe/commands/__init__.py", line 24, in _func
        ret = f(frappe._dict(ctx.obj), *args, **kwargs)
      File "/home/frappe/frappe-bench/apps/frappe/frappe/commands/site.py", line 267, in reload_doctype
        frappe.reload_doctype(doctype, force=context.force)
      File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 682, in reload_doctype
        reload_doc(scrub(db.get_value("DocType", doctype, "module")), "doctype", scrub(doctype),
      File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 708, in scrub
        return txt.replace(' ','_').replace('-', '_').lower()
    AttributeError: 'NoneType' object has no attribute 'replace'

How about try ‘bench clear-cache’ or ‘bench update’ again?

Here’s the code
https://github.com/frappe/frappe/blob/develop/frappe/__init__.py#L761

reload_doc(scrub(db.get_value("DocType", doctype, "module")), "doctype", scrub(doctype),
	force=force, reset_permissions=reset_permissions)

So in your case db.get_value(“DocType”, doctype, “module”) returns a nil object and not a string.

In a ‘bench console’ I get this:

frappe@ubuntu:~/frappe-bench$ bench console
Python 2.7.12 (default, Dec 4 2017, 14:50:18)
Type “copyright”, “credits” or “license” for more information.

IPython 5.5.0 – An enhanced Interactive Python.
? → Introduction and overview of IPython’s features.
%quickref → Quick reference.
help → Python’s own help system.
object? → Details about ‘object’, use ‘object??’ for extra details.

In [1]: dt = frappe.db.get_value(“DocType”, “Domain”, “module”)

In [2]: frappe.scrub(dt)
Out[2]: u’core’

Thank you @clarkej.
Not 100% fixed yet, but your pointers led me to some other things to fix, which I am working on.
I haven’t ever used bench console before, so grateful for the learning opportunity, though I need some more help on this part (please).
if it now says
Migrating site1.local Executing erpnext.patches.v8_9.add_setup_progress_actions #08-09-2017 #26-09-2017 #22-11-2017 #15-12-2017 in site1.local (8de49ae55a02e7ac) Traceback (most recent call last): File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main "__main__", fname, loader, pkg_name) File "/usr/lib/python2.7/runpy.py", line 72, in _run_code exec code in run_globals File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 94, in <module> main() File "/home/frappe/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 18, in main click.Group(commands=commands)(prog_name='bench') File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 722, in __call__ return self.main(*args, **kwargs) File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 697, in main rv = self.invoke(ctx) File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 1066, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 1066, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 895, in invoke return ctx.invoke(self.callback, **ctx.params) File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 535, in invoke return callback(*args, **kwargs) File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/click/decorators.py", line 17, in new_func return f(get_current_context(), *args, **kwargs) File "/home/frappe/frappe-bench/apps/frappe/frappe/commands/__init__.py", line 24, in _func ret = f(frappe._dict(ctx.obj), *args, **kwargs) File "/home/frappe/frappe-bench/apps/frappe/frappe/commands/site.py", line 222, in migrate migrate(context.verbose, rebuild_website=rebuild_website) File "/home/frappe/frappe-bench/apps/frappe/frappe/migrate.py", line 31, in migrate frappe.modules.patch_handler.run_all() File "/home/frappe/frappe-bench/apps/frappe/frappe/modules/patch_handler.py", line 29, in run_all if not run_single(patchmodule = patch): File "/home/frappe/frappe-bench/apps/frappe/frappe/modules/patch_handler.py", line 63, in run_single return execute_patch(patchmodule, method, methodargs) File "/home/frappe/frappe-bench/apps/frappe/frappe/modules/patch_handler.py", line 83, in execute_patch frappe.get_attr(patchmodule.split()[0] + ".execute")() File "/home/frappe/frappe-bench/apps/erpnext/erpnext/patches/v8_9/add_setup_progress_actions.py", line 41, in execute setup_progress.append("actions", action) File "/home/frappe/frappe-bench/apps/frappe/frappe/model/base_document.py", line 138, in append value = self._init_child(value, key) File "/home/frappe/frappe-bench/apps/frappe/frappe/model/base_document.py", line 164, in _init_child value["doctype"] = self.get_table_field_doctype(key) File "/home/frappe/frappe-bench/apps/frappe/frappe/model/base_document.py", line 278, in get_table_field_doctype return self.meta.get_field(fieldname).options AttributeError: 'NoneType' object has no attribute 'options'
what is the correct next step or place to look?
Thanks

ok what I suggest is first to id the problem doctype and its field. To do that add a print statement

def get_table_field_doctype(self, fieldname):
   print 'DocType=' + self.get_name(self) + 'fieldname=' + fieldname
   return self.meta.get_field(fieldname).options

Next the goal is to determine why or whether the options field is NULL for the doctype in question. That info is I think stored in tabDocField, for eg

MariaDB [d56cb677eaab3383]> select parent,fieldname,options from tabDocField where parent like ‘%Customer%’;

Once you know the doctype at issue, you can then determine what or whether the patch action on it is reasonable?

https://github.com/frappe/erpnext/blob/develop/erpnext/patches/v8_9/add_setup_progress_actions.py

1 Like

Thank you - I will try this out and revert ASAP

A possibly easier option is to comment out the patch actions - to say binary search to discover and isolate the problem action?

I tried the suggested method in the reply (2 above here), but it seems I don’t have the required skill/experience :blush: to decipher it. The print line gave me (shown below) … which I am guessing means I didn’t do it right. Although the print statement is there, I don’t think it executed (& I don’t know how to get it to run). I don’t think it is linked to the “bench reload-doctype XXX” parts any longer, as those are now present/correct in the DB.
My suspician is that the DB content is out of whack with the code version as it has been substantially mangled and is a partially recovered set of data from a possibly corrupted system.

Though I would still like to learn how to do the suggested part…the alternative was to comment out the patch actions… I also don’t know and would like to learn how to do this part if there’s a process that can be followed (by a dummy).

Alternatively, I thought I would build a VM from scratch and import the data over that - I just don’t know about version potential mismatch issues (yet)
Thanks again

File “/home/frappe/frappe-bench/apps/frappe/frappe/model/base_document.py”, line 164, in _init_chi ld
value[“doctype”] = self.get_table_field_doctype(key)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/base_document.py”, line 279, in get_table _field_doctype
print ‘DocType=’ + self.get_name(self) + ‘fieldname=’ + fieldname
AttributeError: ‘SetupProgress’ object has no attribute ‘get_name’

Forgive me ‘self.get_name(self)’ was just my guess, and shows I am not qualified in Python scoping and object binding rules. I will investigate and let you know…

1 Like