[CONPY-205] Inconsistent raises based on paramters passed Created: 2022-05-25  Updated: 2022-07-06  Resolved: 2022-05-25

Status: Closed
Project: MariaDB Connector/Python
Component/s: DBAPI 2.0, Generic
Affects Version/s: 1.0.11
Fix Version/s: 1.1.2

Type: Bug Priority: Major
Reporter: Gavin D'souza Assignee: Georg Richter
Resolution: Fixed Votes: 0
Labels: None

Python Version: 3.9.10

 Description   

Inconsistencies Observed:

  • The TypeError message saying "Argument 2 must be Tuple or List!" when Dict is also allowed? This should be a ProgrammingError instead? (ref: https://peps.python.org/pep-0249/#programmingerror)
  • DataError when the number of List/Tuple parameters doesn't match the substitution. No errors raised when extra params passed as Dict...unless there are no parameters to substitute and a Dict has been passed - then we get a TypeError with a misleading error message: "Argument 2 must be Tuple or List!"

```python
In [1]: frappe.db.sql("select 'gavin'")
Out[1]: [('gavin',)]

In [2]: frappe.db.sql("select %s", ("gavin", ))
Out[2]: [('gavin',)]

In [3]: frappe.db.sql("select %(name)s",

{"name": "gavin"}

)
Out[3]: [('gavin',)]

In [4]: frappe.db.sql("select %(name)s",

{"name": "gavin", "Bank": "bfrhsdbuzh"}

)
Out[4]: [('gavin',)]

In [5]: frappe.db.sql("select %(name)s",

{"name": "gavin", "Bank": None}

)
Out[5]: [('gavin',)]

In [6]: frappe.db.sql("select 1",

{"name": "gavin", "Bank": None}

)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
~/Desktop/frappe-bench-dev/apps/frappe/frappe/commands/utils.py in <module>
----> 1 frappe.db.sql("select 1",

{"name": "gavin", "Bank": None}

)

~/Desktop/frappe-bench-dev/apps/frappe/frappe/database/database.py in sql(self, query, values, as_dict, as_list, formatted, debug, ignore_ddl, as_utf8, auto_commit, update, explain, run, pluck)
167 self.log_query(query, values, debug, explain)
168
--> 169 self._cursor.execute(query, values)
170
171 if frappe.flags.in_migrate:

TypeError: Argument 2 must be Tuple or List!

In [7]: frappe.db.sql("select 1", ("gavin", ))
---------------------------------------------------------------------------
DataError Traceback (most recent call last)
~/Desktop/frappe-bench-dev/apps/frappe/frappe/commands/utils.py in <module>
----> 1 frappe.db.sql("select 1", ("gavin", ))

~/Desktop/frappe-bench-dev/apps/frappe/frappe/database/database.py in sql(self, query, values, as_dict, as_list, formatted, debug, ignore_ddl, as_utf8, auto_commit, update, explain, run, pluck)
167 self.log_query(query, values, debug, explain)
168
--> 169 self._cursor.execute(query, values)
170
171 if frappe.flags.in_migrate:

DataError: Invalid number of parameters
```



 Comments   
Comment by Georg Richter [ 2022-05-25 ]

Fixed in 1.1.0

Comment by Gavin D'souza [ 2022-06-08 ]

Hey Georg, what is the release schedule for 1.1.0 like?

Comment by Georg Richter [ 2022-06-08 ]

Hi Gavin,

The plan is to release 1.1.0 GA still in June. There are still some open issues, mainly documentation and a small memory leak.

Generated at Thu Feb 08 03:31:02 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.