fix: pymysql.err.OperationalError: (1054, "Unknown column 'currency' in 'SELECT'") #204
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Relevant Technical Choices
We are creating this PR to fix this issue ==>
value = ['not in', 'Closed, Converted, Lost, Won'] is_default = True _list = <class 'next_crm.overrides.lead.Lead'> default_rows = ['name', 'lead_name', 'customer', 'status', 'email_id', 'mobile_no', 'lead_owner', 'first_name', 'sla_status', 'response_by', 'first_response_time', 'first_responded_on', 'modified', '_assign', 'image'] field = 'modified' enabled_columns = [{'name': 'Cold', 'all_count': 175, 'count': 20, 'color': 'pink', 'order': ['CRM-OPP-2025-00034', 'CRM-OPP-2025-00033', 'CRM-OPP-2025-00032', 'CRM-OPP-2025-00029', 'CRM-OPP-2025-00031', 'CRM-OPP-2025-00025', 'CRM-OPP-2025-00024', 'CRM-OPP-2025-00022', 'CRM-OPP-2025-00021', 'CRM-OPP-2025-00020', 'CRM-OPP-2025-00019', 'CRM-OPP-2025-00018', 'CRM-OPP-2025-00017', 'CRM-OPP-2025-00016', 'CRM-OPP-2025-00015', 'CRM-OPP-2025-00014', 'CRM-OPP-2025-00013', 'CRM-OPP-2025-00012', 'CRM-OPP-2025-00011', 'CRM-OPP-2025-00010']}, {'name': 'Getting Cold', 'all_count': 3, 'count': 3, 'color': 'blue', 'order': ['CRM-OPP-2025-00038', 'CRM-OPP-2025-00037', 'CRM-OPP-2025-00036']}, {'name': 'Warm', 'all_count': 5, 'count': 5, 'color': 'green', 'order': ['CRM-OPP-2025-00023', 'CRM-OPP-2025-00026', 'CRM-OPP-2025-00028', 'CRM-OPP-2025-00039', 'CRM-OPP-2025-00041']}, {'name': 'Hot', 'all_count': 701, 'count': 20, 'color': 'red', 'order': ['CRM-OPP-2025-00035', 'CRM-OPP-2025-00043', 'CRM-OPP-2025-00042', 'CRM-OPP-2... cf_in_filter = False kc = {'name': 'Cold', 'all_count': 175, 'count': 20, 'color': 'pink', 'order': ['CRM-OPP-2025-00034', 'CRM-OPP-2025-00033', 'CRM-OPP-2025-00032', 'CRM-OPP-2025-00029', 'CRM-OPP-2025-00031', 'CRM-OPP-2025-00025', 'CRM-OPP-2025-00024', 'CRM-OPP-2025-00022', 'CRM-OPP-2025-00021', 'CRM-OPP-2025-00020', 'CRM-OPP-2025-00019', 'CRM-OPP-2025-00018', 'CRM-OPP-2025-00017', 'CRM-OPP-2025-00016', 'CRM-OPP-2025-00015', 'CRM-OPP-2025-00014', 'CRM-OPP-2025-00013', 'CRM-OPP-2025-00012', 'CRM-OPP-2025-00011', 'CRM-OPP-2025-00010']} column_filters = {'custom_temperature': 'Cold', 'status': ['not in', 'Closed, Converted, Lost, Won'], 'converted': 0} data = [] group_by_field = 'owner' order = ['CRM-OPP-2025-00034', 'CRM-OPP-2025-00033', 'CRM-OPP-2025-00032', 'CRM-OPP-2025-00029', 'CRM-OPP-2025-00031', 'CRM-OPP-2025-00025', 'CRM-OPP-2025-00024', 'CRM-OPP-2025-00022', 'CRM-OPP-2025-00021', 'CRM-OPP-2025-00020', 'CRM-OPP-2025-00019', 'CRM-OPP-2025-00018', 'CRM-OPP-2025-00017', 'CRM-OPP-2025-00016', 'CRM-OPP-2025-00015', 'CRM-OPP-2025-00014', 'CRM-OPP-2025-00013', 'CRM-OPP-2025-00012', 'CRM-OPP-2025-00011', 'CRM-OPP-2025-00010'] File "apps/next_crm/next_crm/api/doc.py", line 583, in get_records_based_on_order records = frappe.get_list( doctype = 'Lead' rows = ['name', 'customer', 'opportunity_amount', 'status', 'contact_email', 'currency', 'contact_mobile', 'opportunity_owner', 'sla_status', 'response_by', 'first_response_time', 'first_responded_on', 'modified', '_assign', 'title', 'creation', 'modified_by', 'owner', '_liked_by'] filters = [['Lead', 'custom_temperature', '=', 'Cold'], ['Lead', 'status', 'not in', 'Closed, Converted, Lost, Won'], ['Lead', 'converted', '=', 0]] page_length = 20 order = ['CRM-OPP-2025-00034', 'CRM-OPP-2025-00033', 'CRM-OPP-2025-00032', 'CRM-OPP-2025-00029', 'CRM-OPP-2025-00031', 'CRM-OPP-2025-00025', 'CRM-OPP-2025-00024', 'CRM-OPP-2025-00022', 'CRM-OPP-2025-00021', 'CRM-OPP-2025-00020', 'CRM-OPP-2025-00019', 'CRM-OPP-2025-00018', 'CRM-OPP-2025-00017', 'CRM-OPP-2025-00016', 'CRM-OPP-2025-00015', 'CRM-OPP-2025-00014', 'CRM-OPP-2025-00013', 'CRM-OPP-2025-00012', 'CRM-OPP-2025-00011', 'CRM-OPP-2025-00010'] records = [] in_filters = [['Lead', 'custom_temperature', '=', 'Cold'], ['Lead', 'status', 'not in', 'Closed, Converted, Lost, Won'], ['Lead', 'converted', '=', 0], ['Lead', 'name', 'in', ['CRM-OPP-2025-00034', 'CRM-OPP-2025-00033', 'CRM-OPP-2025-00032', 'CRM-OPP-2025-00029', 'CRM-OPP-2025-00031', 'CRM-OPP-2025-00025', 'CRM-OPP-2025-00024', 'CRM-OPP-2025-00022', 'CRM-OPP-2025-00021', 'CRM-OPP-2025-00020', 'CRM-OPP-2025-00019', 'CRM-OPP-2025-00018', 'CRM-OPP-2025-00017', 'CRM-OPP-2025-00016', 'CRM-OPP-2025-00015', 'CRM-OPP-2025-00014', 'CRM-OPP-2025-00013', 'CRM-OPP-2025-00012', 'CRM-OPP-2025-00011', 'CRM-OPP-2025-00010']]] File "apps/frappe/frappe/__init__.py", line 2006, in get_list return frappe.model.db_query.DatabaseQuery(doctype).execute(*args, **kwargs) doctype = 'Lead' args = () kwargs = {'fields': ['name', 'customer', 'opportunity_amount', 'status', 'contact_email', 'currency', 'contact_mobile', 'opportunity_owner', 'sla_status', 'response_by', 'first_response_time', 'first_responded_on', 'modified', '_assign', 'title', 'creation', 'modified_by', 'owner', '_liked_by'], 'filters': [['Lead', 'custom_temperature', '=', 'Cold'], ['Lead', 'status', 'not in', 'Closed, Converted, Lost, Won'], ['Lead', 'converted', '=', 0], ['Lead', 'name', 'in', ['CRM-OPP-2025-00034', 'CRM-OPP-2025-00033', 'CRM-OPP-2025-00032', 'CRM-OPP-2025-00029', 'CRM-OPP-2025-00031', 'CRM-OPP-2025-00025', 'CRM-OPP-2025-00024', 'CRM-OPP-2025-00022', 'CRM-OPP-2025-00021', 'CRM-OPP-2025-00020', 'CRM-OPP-2025-00019', 'CRM-OPP-2025-00018', 'CRM-OPP-2025-00017', 'CRM-OPP-2025-00016', 'CRM-OPP-2025-00015', 'CRM-OPP-2025-00014', 'CRM-OPP-2025-00013', 'CRM-OPP-2025-00012', 'CRM-OPP-2025-00011', 'CRM-OPP-2025-00010']]], 'order_by': 'creation desc', 'page_length': 20} frappe = <module 'frappe' from 'apps/frappe/frappe/__init__.py'> File "apps/frappe/frappe/model/db_query.py", line 191, in execute result = self.build_and_run() self = <frappe.model.db_query.DatabaseQuery object at 0x7f2c16fe41d0> fields = ['name', 'customer', 'opportunity_amount', 'status', 'contact_email', 'currency', 'contact_mobile', 'opportunity_owner', 'sla_status', 'response_by', 'first_response_time', 'first_responded_on', 'modified', '_assign', 'title', 'creation', 'modified_by', 'owner', '_liked_by'] filters = [['Lead', 'custom_temperature', '=', 'Cold'], ['Lead', 'status', 'not in', 'Closed, Converted, Lost, Won'], ['Lead', 'converted', '=', 0], ['Lead', 'name', 'in', ['CRM-OPP-2025-00034', 'CRM-OPP-2025-00033', 'CRM-OPP-2025-00032', 'CRM-OPP-2025-00029', 'CRM-OPP-2025-00031', 'CRM-OPP-2025-00025', 'CRM-OPP-2025-00024', 'CRM-OPP-2025-00022', 'CRM-OPP-2025-00021', 'CRM-OPP-2025-00020', 'CRM-OPP-2025-00019', 'CRM-OPP-2025-00018', 'CRM-OPP-2025-00017', 'CRM-OPP-2025-00016', 'CRM-OPP-2025-00015', 'CRM-OPP-2025-00014', 'CRM-OPP-2025-00013', 'CRM-OPP-2025-00012', 'CRM-OPP-2025-00011', 'CRM-OPP-2025-00010']]] or_filters = None docstatus = None group_by = None order_by = 'creation desc' limit_start = False limit_page_length = 20 as_list = False with_childnames = False debug = False ignore_permissions = False user = None with_comment_count = False join = 'left join' distinct = False start = None page_length = 20 limit = None ignore_ifnull = False save_user_settings = False save_user_settings_fields = False update = None add_total_row = None user_settings = None reference_doctype = None run = True strict = True pluck = None ignore_ddl = False parent_doctype = None File "apps/frappe/frappe/model/db_query.py", line 232, in build_and_run return frappe.db.sql( self = <frappe.model.db_query.DatabaseQuery object at 0x7f2c16fe41d0> args = {'tables': 'tabLead', 'conditions': "where tabLead.custom_temperature = 'Cold' and ifnull(tabLead.status, '') not in ('Closed', 'Converted', 'Lost', 'Won') and tabLead.converted= 0.0 andtabLead.name in ('CRM-OPP-2025-00034', 'CRM-OPP-2025-00033', 'CRM-OPP-2025-00032', 'CRM-OPP-2025-00029', 'CRM-OPP-2025-00031', 'CRM-OPP-2025-00025', 'CRM-OPP-2025-00024', 'CRM-OPP-2025-00022', 'CRM-OPP-2025-00021', 'CRM-OPP-2025-00020', 'CRM-OPP-2025-00019', 'CRM-OPP-2025-00018', 'CRM-OPP-2025-00017', 'CRM-OPP-2025-00016', 'CRM-OPP-2025-00015', 'CRM-OPP-2025-00014', 'CRM-OPP-2025-00013', 'CRM-OPP-2025-00012', 'CRM-OPP-2025-00011', 'CRM-OPP-2025-00010')", 'fields': 'name, customer, status, currency, opportunity_owner, sla_status, response_by, first_response_time, first_responded_on, modified, _assign, title, creation, modified_by, owner, _liked_by', 'order_by': ' order by creation desc', 'group_by': '', 'limit': 'limit 20 offset 0'} query = "select name, customer, status, currency, opportunity_owner, sla_status, response_by, first_response_time, first_responded_on, modified, _assign, title, creation, modified_by, owner, _liked_by\n\t\t\tfrom tabLead\n\t\t\twhere tabLead.custom_temperature = 'Cold' and ifnull(tabLead.status, '') not in ('Closed', 'Converted', 'Lost', 'Won') and tabLead.converted= 0.0 andtabLead.namein ('CRM-OPP-2025-00034', 'CRM-OPP-2025-00033', 'CRM-OPP-2025-00032', 'CRM-OPP-2025-00029', 'CRM-OPP-2025-00031', 'CRM-OPP-2025-00025', 'CRM-OPP-2025-00024', 'CRM-OPP-2025-00022', 'CRM-OPP-2025-00021', 'CRM-OPP-2025-00020', 'CRM-OPP-2025-00019', 'CRM-OPP-2025-00018', 'CRM-OPP-2025-00017', 'CRM-OPP-2025-00016', 'CRM-OPP-2025-00015', 'CRM-OPP-2025-00014', 'CRM-OPP-2025-00013', 'CRM-OPP-2025-00012', 'CRM-OPP-2025-00011', 'CRM-OPP-2025-00010')\n\t\t\t\n\t\t\t order by creation desc\n\t\t\tlimit 20 offset 0" File "apps/frappe/frappe/database/database.py", line 230, in sql self._cursor.execute(query, values) self = <frappe.database.mariadb.database.MariaDBDatabase object at 0x7f2c14028ed0> query = "selectname, customer, status, currency, opportunity_owner, sla_status, response_by, first_response_time, first_responded_on, modified, _assign, title, creation, modified_by, owner, _liked_by\n\t\t\tfrom tabLead\n\t\t\twhere tabLead.custom_temperature = 'Cold' and coalesce(tabLead.status, '') not in ('Closed', 'Converted', 'Lost', 'Won') and tabLead.converted= 0.0 andtabLead.namein ('CRM-OPP-2025-00034', 'CRM-OPP-2025-00033', 'CRM-OPP-2025-00032', 'CRM-OPP-2025-00029', 'CRM-OPP-2025-00031', 'CRM-OPP-2025-00025', 'CRM-OPP-2025-00024', 'CRM-OPP-2025-00022', 'CRM-OPP-2025-00021', 'CRM-OPP-2025-00020', 'CRM-OPP-2025-00019', 'CRM-OPP-2025-00018', 'CRM-OPP-2025-00017', 'CRM-OPP-2025-00016', 'CRM-OPP-2025-00015', 'CRM-OPP-2025-00014', 'CRM-OPP-2025-00013', 'CRM-OPP-2025-00012', 'CRM-OPP-2025-00011', 'CRM-OPP-2025-00010')\n\t\t\t\n\t\t\t order by creation desc\n\t\t\tlimit 20 offset 0 /* FRAPPE_TRACE_ID: 09cd5981-2947-4337-a6b0-da4b7cd7c9e7... values = None as_dict = True as_list = 0 debug = False ignore_ddl = False auto_commit = 0 update = None explain = False run = True pluck = False as_iterator = False trace_id = '09cd5981-2947-4337-a6b0-da4b7cd7c9e7' File "env/lib/python3.11/site-packages/pymysql/cursors.py", line 153, in execute result = self._query(query) self = <pymysql.cursors.Cursor object at 0x7f2c122676d0> query = "selectname, customer, status, currency, opportunity_owner, sla_status, response_by, first_response_time, first_responded_on, modified, _assign, title, creation, modified_by, owner, _liked_by\n\t\t\tfrom tabLead\n\t\t\twhere tabLead.custom_temperature = 'Cold' and coalesce(tabLead.status, '') not in ('Closed', 'Converted', 'Lost', 'Won') and tabLead.converted= 0.0 andtabLead.namein ('CRM-OPP-2025-00034', 'CRM-OPP-2025-00033', 'CRM-OPP-2025-00032', 'CRM-OPP-2025-00029', 'CRM-OPP-2025-00031', 'CRM-OPP-2025-00025', 'CRM-OPP-2025-00024', 'CRM-OPP-2025-00022', 'CRM-OPP-2025-00021', 'CRM-OPP-2025-00020', 'CRM-OPP-2025-00019', 'CRM-OPP-2025-00018', 'CRM-OPP-2025-00017', 'CRM-OPP-2025-00016', 'CRM-OPP-2025-00015', 'CRM-OPP-2025-00014', 'CRM-OPP-2025-00013', 'CRM-OPP-2025-00012', 'CRM-OPP-2025-00011', 'CRM-OPP-2025-00010')\n\t\t\t\n\t\t\t order by creation desc\n\t\t\tlimit 20 offset 0 /* FRAPPE_TRACE_ID: 09cd5981-2947-4337-a6b0-da4b7cd7c9e7... args = None File "env/lib/python3.11/site-packages/pymysql/cursors.py", line 322, in _query conn.query(q) self = <pymysql.cursors.Cursor object at 0x7f2c122676d0> q = "selectname, customer, status, currency, opportunity_owner, sla_status, response_by, first_response_time, first_responded_on, modified, _assign, title, creation, modified_by, owner, _liked_by\n\t\t\tfrom tabLead\n\t\t\twhere tabLead.custom_temperature = 'Cold' and coalesce(tabLead.status, '') not in ('Closed', 'Converted', 'Lost', 'Won') and tabLead.converted= 0.0 andtabLead.namein ('CRM-OPP-2025-00034', 'CRM-OPP-2025-00033', 'CRM-OPP-2025-00032', 'CRM-OPP-2025-00029', 'CRM-OPP-2025-00031', 'CRM-OPP-2025-00025', 'CRM-OPP-2025-00024', 'CRM-OPP-2025-00022', 'CRM-OPP-2025-00021', 'CRM-OPP-2025-00020', 'CRM-OPP-2025-00019', 'CRM-OPP-2025-00018', 'CRM-OPP-2025-00017', 'CRM-OPP-2025-00016', 'CRM-OPP-2025-00015', 'CRM-OPP-2025-00014', 'CRM-OPP-2025-00013', 'CRM-OPP-2025-00012', 'CRM-OPP-2025-00011', 'CRM-OPP-2025-00010')\n\t\t\t\n\t\t\t order by creation desc\n\t\t\tlimit 20 offset 0 /* FRAPPE_TRACE_ID: 09cd5981-2947-4337-a6b0-da4b7cd7c9e7... conn = <pymysql.connections.Connection object at 0x7f2c12266b90> File "env/lib/python3.11/site-packages/pymysql/connections.py", line 563, in query self._affected_rows = self._read_query_result(unbuffered=unbuffered) self = <pymysql.connections.Connection object at 0x7f2c12266b90> sql = b"selectname, customer, status, currency, opportunity_owner, sla_status, response_by, first_response_time, first_responded_on, modified, _assign, title, creation, modified_by, owner, _liked_by\n\t\t\tfrom tabLead\n\t\t\twhere tabLead.custom_temperature = 'Cold' and coalesce(tabLead.status, '') not in ('Closed', 'Converted', 'Lost', 'Won') and tabLead.converted= 0.0 andtabLead.name in ('CRM-OPP-2025-00034', 'CRM-OPP-2025-00033', 'CRM-OPP-2025-00032', 'CRM-OPP-2025-00029', 'CRM-OPP-2025-00031', 'CRM-OPP-2025-00025', 'CRM-OPP-2025-00024', 'CRM-OPP-2025-00022', 'CRM-OPP-2025-00021', 'CRM-OPP-2025-00020', 'CRM-OPP-2025-00019', 'CRM-OPP-2025-00018', 'CRM-OPP-2025-00017', 'CRM-OPP-2025-00016', 'CRM-OPP-2025-00015', 'CRM-OPP-2025-00014', 'CRM-OPP-2025-00013', 'CRM-OPP-2025-00012', 'CRM-OPP-2025-00011', 'CRM-OPP-2025-00010')\n\t\t\t\n\t\t\t order by creation desc\n\t\t\tlimit 20 offset 0 /* FRAPPE_TRACE_ID: 09cd5981-2947-4337-a6b0-da4b7cd7c9e... unbuffered = False File "env/lib/python3.11/site-packages/pymysql/connections.py", line 825, in _read_query_result result.read() self = <pymysql.connections.Connection object at 0x7f2c12266b90> unbuffered = False result = <pymysql.connections.MySQLResult object at 0x7f2c12264610> File "env/lib/python3.11/site-packages/pymysql/connections.py", line 1199, in read first_packet = self.connection._read_packet() self = <pymysql.connections.MySQLResult object at 0x7f2c12264610> File "env/lib/python3.11/site-packages/pymysql/connections.py", line 775, in _read_packet packet.raise_for_error() self = <pymysql.connections.Connection object at 0x7f2c12266b90> packet_type = <class 'pymysql.protocol.MysqlPacket'> buff = bytearray(b"\xff\x1e\x04#42S22Unknown column \'currency\' in \'SELECT\'") packet_header = b'.\x00\x00\x01' btrl = 46 btrh = 0 packet_number = 1 bytes_to_read = 46 recv_data = b"\xff\x1e\x04#42S22Unknown column 'currency' in 'SELECT'" packet = <pymysql.protocol.MysqlPacket object at 0x7f2c3741f190> File "env/lib/python3.11/site-packages/pymysql/protocol.py", line 219, in raise_for_error err.raise_mysql_exception(self._data) self = <pymysql.protocol.MysqlPacket object at 0x7f2c3741f190> errno = 1054 File "env/lib/python3.11/site-packages/pymysql/err.py", line 150, in raise_mysql_exception raise errorclass(errno, errval) data = b"\xff\x1e\x04#42S22Unknown column 'currency' in 'SELECT'" errno = 1054 errval = "Unknown column 'currency' in 'SELECT'" errorclass = <class 'pymysql.err.OperationalError'> pymysql.err.OperationalError: (1054, "Unknown column 'currency' in 'SELECT'")
Testing Instructions
To fix this issue we open new field in Lead Doctype , field name is currency.
Additional Information:
Screenshot/Screencast
Checklist
Fixes #