Why is there a discrepancy between frappe.db.count and frappe.db.get_value?

There is one record ToDo in my db. I tried this:

In [1]: frappe.db.count("ToDo")
Out[1]: 1L

but when I do this: value = frappe.db.get_value("ToDo", "description"), the value is None.

Why did I do wrong here ?

@The_Lowkster, frappe.db.get_value, expect the second value to be used in filter, so if you pass:

frappe.db.get_value("ToDo", "description") the resulting SQL will be
SELECT name FROM tabToDo where name="description"

If do you need get a list of values, use frappe.get_list
frappe.get_list("ToDo", fields=["description"])

Those two have different uses.

frappe.db.count() returns the count for a DocType.
frappe.db.get_value()" gets a specific value according to parameters entered.

Usage :

frappe.db.get_value("User", "Administrator", "email" ) will get the email for the Administrator user.

Ah! I see.

In [1]: data = frappe.get_list("ToDo", fields=["description"])

In [2]: data
Out[2]: [{'description': u'testing'}]


Just as a follow up to this, someone please correct my understanding of this. “ToDo” is doc type right ? So how come this: frappe.get_doc("ToDo") returns an error saying that ToDo ToDo not found ?

Nevermind. As an answer to my own question, it should be this way:

data = frappe.get_doc("ToDo", {'description': 'testing'})

1 Like