Error creating sales tree [SQL Error]

Hi i tried to create the sales tree, or item group tree its giving me the below error

Traceback (most recent call last):


  File "/opt/bench/erpnext/apps/frappe/frappe/app.py", line 62, in application
    response = frappe.handler.handle()
  File "/opt/bench/erpnext/apps/frappe/frappe/handler.py", line 22, in handle
    data = execute_cmd(cmd)
  File "/opt/bench/erpnext/apps/frappe/frappe/handler.py", line 53, in execute_cmd
    return frappe.call(method, **frappe.form_dict)
  File "/opt/bench/erpnext/apps/frappe/frappe/__init__.py", line 942, in call
    return fn(*args, **newargs)
  File "/opt/bench/erpnext/apps/frappe/frappe/desk/treeview.py", line 50, in get_children
    order_by='name')
  File "/opt/bench/erpnext/apps/frappe/frappe/__init__.py", line 1153, in get_list
    return frappe.model.db_query.DatabaseQuery(doctype).execute(None, *args, **kwargs)
  File "/opt/bench/erpnext/apps/frappe/frappe/model/db_query.py", line 87, in execute
    result = self.build_and_run()
  File "/opt/bench/erpnext/apps/frappe/frappe/model/db_query.py", line 111, in build_and_run
    return frappe.db.sql(query, as_dict=not self.as_list, debug=self.debug, update=self.update)
  File "/opt/bench/erpnext/apps/frappe/frappe/database.py", line 209, in sql
    self._cursor.execute(query)
  File "/opt/bench/erpnext/env/local/lib/python2.7/site-packages/pymysql/cursors.py", line 170, in execute
    result = self._query(query)
  File "/opt/bench/erpnext/env/local/lib/python2.7/site-packages/pymysql/cursors.py", line 328, in _query
    conn.query(q)
  File "/opt/bench/erpnext/env/local/lib/python2.7/site-packages/pymysql/connections.py", line 893, in query
    self._affected_rows = self._read_query_result(unbuffered=unbuffered)
  File "/opt/bench/erpnext/env/local/lib/python2.7/site-packages/pymysql/connections.py", line 1103, in _read_query_result
    result.read()
  File "/opt/bench/erpnext/env/local/lib/python2.7/site-packages/pymysql/connections.py", line 1396, in read
    first_packet = self.connection._read_packet()
  File "/opt/bench/erpnext/env/local/lib/python2.7/site-packages/pymysql/connections.py", line 1059, in _read_packet
    packet.check_error()
  File "/opt/bench/erpnext/env/local/lib/python2.7/site-packages/pymysql/connections.py", line 384, in check_error
    err.raise_mysql_exception(self._data)
  File "/opt/bench/erpnext/env/local/lib/python2.7/site-packages/pymysql/err.py", line 109, in raise_mysql_exception
    raise errorclass(errno, errval)
ProgrammingError: (1064, u'You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near \') = "" and ifnull(`tabCustomer Group`.docstatus, "") < "2"\n\t\t\t  order by name\' at line 1')

Please specify your branch or version and steps to replicate.

Sir I am on develop branch, with version 11 installed

Even in our site, we are not able to submit purchase Orders. We are thrown up with the same mysql syntax error. Attaching the server log here.

Traceback (most recent call last):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/desk/form/save.py", line 19, in savedocs
    doc.submit()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 857, in submit
    self._submit()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 846, in _submit
    self.save()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 259, in save
    return self._save(*args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 295, in _save
    self.run_before_save_methods()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 890, in run_before_save_methods
    self.run_method("validate")
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 781, in run_method
    out = Document.hook(fn)(self, *args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 1059, in composer
    return composed(self, method, *args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 1042, in runner
    add_to_return_value(self, fn(self, *args, **kwargs))
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 775, in <lambda>
    fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/buying/doctype/purchase_order/purchase_order.py", line 37, in validate
    super(PurchaseOrder, self).validate()
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/buying_controller.py", line 34, in validate
    super(BuyingController, self).validate()
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/stock_controller.py", line 17, in validate
    super(StockController, self).validate()
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/accounts_controller.py", line 40, in validate
    self.set_missing_values(for_validate=True)
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/buying_controller.py", line 68, in set_missing_values
    self.update_if_missing(get_party_details(self.supplier, party_type="Supplier", ignore_permissions=self.flags.ignore_permissions, doctype=self.doctype, company=self.company))
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/party.py", line 33, in get_party_details
    company, posting_date, price_list, currency, doctype, ignore_permissions, fetch_payment_terms_template)
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/party.py", line 52, in _get_party_details
    out["taxes_and_charges"] = set_taxes(party.name, party_type, posting_date, company, out.customer_group, out.supplier_type)
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/party.py", line 362, in set_taxes
    return get_tax_template(posting_date, args)
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/doctype/tax_rule/tax_rule.py", line 147, in get_tax_template
    where {0}""".format(" and ".join(conditions)), as_dict = True)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/database/database.py", line 165, in sql
    self._cursor.execute(query)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/cursors.py", line 165, in execute
    result = self._query(query)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/cursors.py", line 321, in _query
    conn.query(q)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/connections.py", line 860, in query
    self._affected_rows = self._read_query_result(unbuffered=unbuffered)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/connections.py", line 1061, in _read_query_result
    result.read()
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/connections.py", line 1349, in read
    first_packet = self.connection._read_packet()
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/connections.py", line 1018, in _read_packet
    packet.check_error()
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/connections.py", line 384, in check_error
    err.raise_mysql_exception(self._data)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/err.py", line 107, in raise_mysql_exception
    raise errorclass(errno, errval)
ProgrammingError: (1064, u"You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'Coimbatore'') and coalesce(tax_type, '') in ('', ''Purchase'') and coalesce(bill' at line 3")

Traceback (most recent call last):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/app.py", line 55, in application
    response = frappe.handler.handle()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 20, in handle
    data = execute_cmd(cmd)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 55, in execute_cmd
    return frappe.call(method, **frappe.form_dict)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 1007, in call
    return fn(*args, **newargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/desk/form/save.py", line 19, in savedocs
    doc.submit()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 857, in submit
    self._submit()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 846, in _submit
    self.save()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 259, in save
    return self._save(*args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 295, in _save
    self.run_before_save_methods()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 890, in run_before_save_methods
    self.run_method("validate")
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 781, in run_method
    out = Document.hook(fn)(self, *args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 1059, in composer
    return composed(self, method, *args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 1042, in runner
    add_to_return_value(self, fn(self, *args, **kwargs))
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 775, in <lambda>
    fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/buying/doctype/purchase_order/purchase_order.py", line 37, in validate
    super(PurchaseOrder, self).validate()
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/buying_controller.py", line 34, in validate
    super(BuyingController, self).validate()
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/stock_controller.py", line 17, in validate
    super(StockController, self).validate()
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/accounts_controller.py", line 40, in validate
    self.set_missing_values(for_validate=True)
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/buying_controller.py", line 68, in set_missing_values
    self.update_if_missing(get_party_details(self.supplier, party_type="Supplier", ignore_permissions=self.flags.ignore_permissions, doctype=self.doctype, company=self.company))
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/party.py", line 33, in get_party_details
    company, posting_date, price_list, currency, doctype, ignore_permissions, fetch_payment_terms_template)
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/party.py", line 52, in _get_party_details
    out["taxes_and_charges"] = set_taxes(party.name, party_type, posting_date, company, out.customer_group, out.supplier_type)
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/party.py", line 362, in set_taxes
    return get_tax_template(posting_date, args)
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/doctype/tax_rule/tax_rule.py", line 147, in get_tax_template
    where {0}""".format(" and ".join(conditions)), as_dict = True)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/database/database.py", line 165, in sql
    self._cursor.execute(query)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/cursors.py", line 165, in execute
    result = self._query(query)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/cursors.py", line 321, in _query
    conn.query(q)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/connections.py", line 860, in query
    self._affected_rows = self._read_query_result(unbuffered=unbuffered)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/connections.py", line 1061, in _read_query_result
    result.read()
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/connections.py", line 1349, in read
    first_packet = self.connection._read_packet()
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/connections.py", line 1018, in _read_packet
    packet.check_error()
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/connections.py", line 384, in check_error
    err.raise_mysql_exception(self._data)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/err.py", line 107, in raise_mysql_exception
    raise errorclass(errno, errval)
ProgrammingError: (1064, u"You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'Coimbatore'') and coalesce(tax_type, '') in ('', ''Purchase'') and coalesce(bill' at line 3")

If you are on develop branch maybe move to staging to stay on V11?

See this recent change

After i performed the steps suggested by Mr.Mehta, the portal itself is not opening. Getting Internal Server Error.

“Getting Internal Server Error.”

This is a general message - you should have gotten a more detailed one.

Please start a new thread and share the traceback found in the logs, for eg here ~/frappe-bench/logs/web.error.log