Repository: frappe/frappe

Issue:
bench rebuild-global-search fails on single doctypes
When /frappe/utils/global_search.py comes across a single table, the call to frappe.get_all(...) fails.

## Steps to reproduce the issue

install erpnext f12.x.x on frappe 12.x.x
run bench rebuild-global-search
--> it will fail in a erpnext single table (like "'Quick Stock Balance")

### Stacktrace / full error message

```
Traceback (most recent call last):
  File "/usr/lib/python3.5/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.5/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/bob/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 97, in <module>
    main()
  File "/home/bob/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 18, in main
    click.Group(commands=commands)(prog_name='bench')
  File "/home/bob/frappe-bench/env/lib/python3.5/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/home/bob/frappe-bench/env/lib/python3.5/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/home/bob/frappe-bench/env/lib/python3.5/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/bob/frappe-bench/env/lib/python3.5/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/bob/frappe-bench/env/lib/python3.5/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/bob/frappe-bench/env/lib/python3.5/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/home/bob/frappe-bench/env/lib/python3.5/site-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/bob/frappe-bench/apps/frappe/frappe/commands/__init__.py", line 25, in _func
    ret = f(frappe._dict(ctx.obj), *args, **kwargs)
  File "/home/bob/frappe-bench/apps/frappe/frappe/commands/utils.py", line 677, in rebuild_global_search
    rebuild_for_doctype(doctype)
  File "/home/bob/frappe-bench/apps/frappe/frappe/utils/global_search.py", line 101, in rebuild_for_doctype
    all_records = frappe.get_all(doctype, fields=fieldnames, filters=_get_filters())
  File "/home/bob/frappe-bench/apps/frappe/frappe/__init__.py", line 1302, in get_all
    return get_list(doctype, *args, **kwargs)
  File "/home/bob/frappe-bench/apps/frappe/frappe/__init__.py", line 1275, in get_list
    return frappe.model.db_query.DatabaseQuery(doctype).execute(None, *args, **kwargs)
  File "/home/bob/frappe-bench/apps/frappe/frappe/model/db_query.py", line 96, in execute
    result = self.build_and_run()
  File "/home/bob/frappe-bench/apps/frappe/frappe/model/db_query.py", line 110, in build_and_run
    args = self.prepare_args()
  File "/home/bob/frappe-bench/apps/frappe/frappe/model/db_query.py", line 136, in prepare_args
    self.set_optional_columns()
  File "/home/bob/frappe-bench/apps/frappe/frappe/model/db_query.py", line 294, in set_optional_columns
    columns = get_table_columns(self.doctype)
  File "/home/bob/frappe-bench/apps/frappe/frappe/model/meta.py", line 49, in get_table_columns
    return frappe.db.get_table_columns(doctype)
  File "/home/bob/frappe-bench/apps/frappe/frappe/database/database.py", line 864, in get_table_columns
    raise self.TableMissingError('DocType', doctype)
pymysql.err.ProgrammingError: ('DocType', 'Quick Stock Balance')

```
### quick fix:
I added a 
`if (cint(meta.issingle) == 1):  
		return
`

to `def _get_filters():` line 85ff, but I it will  not be searching single tables.


Discussion:
I am running into the exact same issue...Would love to have it fixed. IN the meantime, how do I do the step above? Where do I put in that code? Thanks!
I added this in frappe/utils/global_search.py, at around line 85, just after "meta = frappe.get_meta(doctype)"
Alias, Thanks for the clear instructions! I will give this a try. We've been struggling mightily with not being able to reliably search, and I'm hoping the global search rebuild will help!
That let the rebuild go through! Search is working better-ish. Still not finding everything. But, better.
I found another problem recently (https://github.com/frappe/frappe/pull/8936), but I think that went into develop since.
Same issue here.

`  File "/home/frappe/frappe-bench/apps/frappe/frappe/database/database.py", line 865, in get_table_columns
    raise self.TableMissingError('DocType', doctype)
pymysql.err.ProgrammingError: (u'DocType', u'Quick Stock Balance')`

Resolving patch:
diff --git a/frappe/utils/global_search.py b/frappe/utils/global_search.py
--- a/frappe/utils/global_search.py
+++ b/frappe/utils/global_search.py
@@ -81,6 +81,10 @@ def _get_filters():
 		return filters
 
 	meta = frappe.get_meta(doctype)
+	
+	if cint(meta.issingle) == 1:
+		return
+	
 	if cint(meta.istable) == 1:
 		parent_doctypes = frappe.get_all("DocField", fields="parent", filters={
 			"fieldtype": ["in", frappe.model.table_fields],


Test patch: