Jaymon / prom

A PostgreSQL or SQLite orm for Python
MIT License
22 stars 4 forks source link

Error binding parameter needs to print a better exception #69

Closed Jaymon closed 1 year ago

Jaymon commented 6 years ago

This is what I got:

Traceback (most recent call last):
  File "/root/venv/lib/python3.6/site-packages/prom/interface/base.py", line 189, in connection
    yield connection
  File "/root/venv/lib/python3.6/site-packages/prom/interface/base.py", line 619, in _query
    cur.execute(query_str, query_args)
sqlite3.InterfaceError: Error binding parameter 2 - probably unsupported type.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/root/glyph/__main__.py", line 513, in <module>
    exit(__name__)
  File "/root/venv/lib/python3.6/site-packages/captain/__init__.py", line 105, in exit
    ret_code = s.run(raw_args)
  File "/root/venv/lib/python3.6/site-packages/captain/__init__.py", line 240, in run
    ret_code = callback(*args, **kwargs)
  File "/root/glyph/__main__.py", line 507, in main_search
    for emoji_unicode in q.values():
  File "/root/venv/lib/python3.6/site-packages/prom/query.py", line 1063, in values
    return self.get(limit=limit, page=page).values()
  File "/root/venv/lib/python3.6/site-packages/prom/query.py", line 1023, in get
    results = self._query('get')
  File "/root/venv/lib/python3.6/site-packages/prom/query.py", line 1277, in _query
    return getattr(i, method_name)(s, self, **kwargs) # i.method_name(schema, query)
  File "/root/venv/lib/python3.6/site-packages/prom/interface/base.py", line 494, in get
    ret = self._get_query(self._get, schema, query, **kwargs)
  File "/root/venv/lib/python3.6/site-packages/prom/decorators.py", line 60, in wrapper
    return func(self, *args, **kwargs)
  File "/root/venv/lib/python3.6/site-packages/prom/interface/base.py", line 466, in _get_query
    self.raise_error(e, exc_info)
  File "/root/venv/lib/python3.6/site-packages/prom/interface/base.py", line 567, in raise_error
    reraise(e.__class__, e, exc_info[2])
  File "/root/venv/lib/python3.6/site-packages/prom/compat.py", line 68, in reraise
    raise value
  File "/root/venv/lib/python3.6/site-packages/prom/interface/base.py", line 459, in _get_query
    ret = callback(schema, query, *args, **kwargs)
  File "/root/venv/lib/python3.6/site-packages/prom/interface/base.py", line 900, in _get
    return self.query(query_str, *query_args, **kwargs)
  File "/root/venv/lib/python3.6/site-packages/prom/interface/base.py", line 227, in query
    return self._query(query_str, query_args, **query_options)
  File "/root/venv/lib/python3.6/site-packages/prom/interface/base.py", line 639, in _query
    return ret
  File "/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/contextlib.py", line 99, in __exit__
    self.gen.throw(type, value, traceback)
  File "/root/venv/lib/python3.6/site-packages/prom/interface/base.py", line 204, in connection
    self.raise_error(e)
  File "/root/venv/lib/python3.6/site-packages/prom/interface/base.py", line 567, in raise_error
    reraise(e.__class__, e, exc_info[2])
  File "/root/venv/lib/python3.6/site-packages/prom/compat.py", line 67, in reraise
    raise value.with_traceback(tb)
  File "/root/venv/lib/python3.6/site-packages/prom/interface/base.py", line 189, in connection
    yield connection
  File "/root/venv/lib/python3.6/site-packages/prom/interface/base.py", line 619, in _query
    cur.execute(query_str, query_args)
prom.exception.InterfaceError: Error binding parameter 2 - probably unsupported type.

It would be way more helpful if it printed out what the parameters where, in this case I was passing param q but I had just named my query q so I was basically passing the Query to itself, when I printed the query vals everything made sense:

(0, -1, <prom.query.Query object at 0x10ce4e668>)

Here is my query:

q = Foo.query.select_foo()
q.in_bar(bars).is_che(q).asc_baz()

Notice the is_che(q), q was previously the passed in search question but I redefined it to the prom.query.Query instance. The stacktrace and error should've been more descriptive to get me to that realization faster