Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider using enable_callback_tracebacks(True) #891

Closed
simonw opened this issue Jul 8, 2020 · 5 comments
Closed

Consider using enable_callback_tracebacks(True) #891

simonw opened this issue Jul 8, 2020 · 5 comments

Comments

@simonw
Copy link
Owner

simonw commented Jul 8, 2020

From https://docs.python.org/3/library/sqlite3.html#sqlite3.enable_callback_tracebacks

sqlite3.``enable_callback_tracebacks(flag)

By default you will not get any tracebacks in user-defined functions, aggregates, converters, authorizer callbacks etc. If you want to debug them, you can call this function with flag set to True. Afterwards, you will get tracebacks from callbacks on sys.stderr. Use False to disable the feature again.

Maybe turn this on for all of Datasette? Are there any disadvantages to doing that?

@simonw simonw added the research label Jul 8, 2020
@simonw
Copy link
Owner Author

simonw commented Sep 15, 2020

peter-wangxu/persist-queue#74 warns that this might not work with PyPy.

I could solve that with:

if hasattr(sqlite3, "enable_callback_tracebacks"):
    sqlite3.enable_callback_tracebacks(True)

@simonw
Copy link
Owner Author

simonw commented Sep 15, 2020

I've been trying to figure out why this is an optional setting that defaults to off.

I think it's because it writes directly to stderr, so the maintainers of sqlite3 reasonably decided that people should be able to opt in to that rather than having weird stuff show up on stderr that they weren't expecting.

@simonw
Copy link
Owner Author

simonw commented Sep 15, 2020

Here's the commit (from 15 years ago) where enable_callback_tracebacks was first added: ghaering/pysqlite@1e8bd36

  • Exceptions in callbacks lead to the query being aborted now instead of silently leading to generating values.
  • Exceptions in callbacks can be echoed to stderr if you call the module level function enable_callback_tracebacks: enable_callback_tracebacks(1).

@simonw
Copy link
Owner Author

simonw commented Sep 15, 2020

I'm going to turn this on. If people complain about it I can turn it off again (or make it a configuration setting).

@simonw
Copy link
Owner Author

simonw commented Sep 15, 2020

Here's what that looks like:

Traceback (most recent call last):
  File "/Users/simon/Dropbox/Development/datasette/plugins/sql_error.py", line 5, in oh_no_error
    return 100 / 0
ZeroDivisionError: division by zero
ERROR: conn=<sqlite3.Connection object at 0x10bce0030>, sql = 'select oh_no_error()', params = {}: user-defined function raised exception
INFO:     127.0.0.1:54066 - "GET /data?sql=select+oh_no_error%28%29 HTTP/1.1" 400 Bad Request

@simonw simonw closed this as completed in 432a3d6 Sep 15, 2020
simonw added a commit that referenced this issue Oct 1, 2020
@simonw simonw added this to the Datasette 0.50 milestone Oct 8, 2020
simonw added a commit that referenced this issue Oct 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant