Uploaded image for project: 'MariaDB Connector/Python'
  1. MariaDB Connector/Python
  2. CONPY-205

Inconsistent raises based on paramters passed

    XMLWordPrintable

    Details

    • 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
      ```

        Attachments

          Activity

            People

            Assignee:
            georg Georg Richter
            Reporter:
            gavin Gavin D'souza
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.