frappe.get_value({'doctype':'Company'}) query error - encoding issue?

When run in a ‘bench console’ this query errors, my guess is due I think to a encoding issue.

What must I do for this to work correctly?

Thanks very much!

In [1]: frappe.get_value({‘doctype’:‘Company’})


ProgrammingError Traceback (most recent call last)
/home/frappe/frappe-bench/apps/frappe/frappe/commands/utils.pyc in ()
----> 1 frappe.get_value({‘doctype’:‘Company’})

/home/frappe/frappe-bench/apps/frappe/frappe/init.pyc in get_value(*args, **kwargs)
1189 :param debug: Print query in error log.
1190 “”"
-> 1191 return db.get_value(*args, **kwargs)
1192
1193 def as_json(obj, indent=1):

/home/frappe/frappe-bench/apps/frappe/frappe/database.pyc in get_value(self, doctype, filters, fieldname, ignore, as_dict, debug, order_by, cache)
441
442 ret = self.get_values(doctype, filters, fieldname, ignore, as_dict, debug,
–> 443 order_by, cache=cache)
444
445 return ((len(ret[0]) > 1 or as_dict) and ret[0] or ret[0][0]) if ret else None

/home/frappe/frappe-bench/apps/frappe/frappe/database.pyc in get_values(self, doctype, filters, fieldname, ignore, as_dict, debug, order_by, update, cache)
496 raise
497 else:
–> 498 out = self.get_values_from_single(fields, filters, doctype, as_dict, debug, update)
499
500 if cache and isinstance(filters, string_types):

/home/frappe/frappe-bench/apps/frappe/frappe/database.pyc in get_values_from_single(self, fields, filters, doctype, as_dict, debug, update)
532 from tabSingles where field in (%s) and doctype=%s"""
533 % (’, ‘.join([’%s’] * len(fields)), ‘%s’),
–> 534 tuple(fields) + (doctype,), as_dict=False, debug=debug)
535
536 if as_dict:

/home/frappe/frappe-bench/apps/frappe/frappe/database.pyc in sql(self, query, values, as_dict, as_list, formatted, debug, ignore_ddl, as_utf8, auto_commit, update)
164 frappe.log(values)
165 frappe.log(">>>>")
–> 166 self._cursor.execute(query, values)
167 else:
168 if debug:

/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/cursors.pyc in execute(self, query, args)
163 query = self.mogrify(query, args)
164
–> 165 result = self._query(query)
166 self._executed = query
167 return result

/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/cursors.pyc in _query(self, q)
319 conn = self._get_db()
320 self._last_executed = q
–> 321 conn.query(q)
322 self._do_get_result()
323 return self.rowcount

/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/connections.pyc in query(self, sql, unbuffered)
858 sql = sql.encode(self.encoding, ‘surrogateescape’)
859 self._execute_command(COMMAND.COM_QUERY, sql)
–> 860 self._affected_rows = self._read_query_result(unbuffered=unbuffered)
861 return self._affected_rows
862

/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/connections.pyc in _read_query_result(self, unbuffered)
1059 else:
1060 result = MySQLResult(self)
-> 1061 result.read()
1062 self._result = result
1063 if result.server_status is not None:

/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/connections.pyc in read(self)
1347 def read(self):
1348 try:
-> 1349 first_packet = self.connection._read_packet()
1350
1351 if first_packet.is_ok_packet():

/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/connections.pyc in _read_packet(self, packet_type)
1016
1017 packet = packet_type(buff, self.encoding)
-> 1018 packet.check_error()
1019 return packet
1020

/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/connections.pyc in check_error(self)
382 errno = self.read_uint16()
383 if DEBUG: print(“errno =”, errno)
–> 384 err.raise_mysql_exception(self._data)
385
386 def dump(self):

/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/pymysql/err.pyc in raise_mysql_exception(data)
105 errval = data[3:].decode(‘utf-8’, ‘replace’)
106 errorclass = error_map.get(errno, InternalError)
–> 107 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 ‘: u"‘Company’"}’ at line 2’)

Hello, I don’t think this is a valid syntax for get_value, it makes an invalid SQL statement.
What are you trying to achieve?

“What are you trying to achieve?”

Just learning and debugging!

I seek simply a working get_value(*args, **kwargs) case.

For eg this get_all(doctype, *args, **kwargs) query works fine

In [5]: frappe.get_all(‘Company’, fields=[‘name’])
Out[5]: [{u’name’: u’Bent Pin Solutions Ltd’}]

Seems that get_value works only for retrieve a document property.

frappe.db.get_value(“Selling Settings”, None, “selling_price_list”)
frappe.db.get_value(“Employee”, {“user_id”: d.sender}, “employee_name”)
frappe.db.get_value(“Sales Person”, sales_person, “employee”)
frappe.db.get_value(“Serial No”, serial_no, [“warranty_expiry_date”, “amc_expiry_date”, “warehouse”, “delivery_date”], as_dict=1)

It’s okay that you are learning and debugging, I ask you what are you trying to achieve just with the will to help.

Muchas gracias por los exemplos Federico!