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

Use sqlalchemy customised serializers #6

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions tgext/debugbar/sections/sqla.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def default(self, obj):
return str(obj)
else:
return json.JSONEncoder.default(self, obj)
json_encoder = ExtendedJSONEncoder()
json_encoder = lambda x: json.dumps(x, cls=ExtendedJSONEncoder)

import tg
from tg import config, request, app_globals
Expand Down Expand Up @@ -89,6 +89,9 @@ def title(self):
return _('SQLAlchemy')

def _gather_queries(self):
if "sqlalchemy.json_serializer" in config:
json_encoder = config["sqlalchemy.json_serializer"]

queries = getattr(request, 'tgdb_sqla_queries', [])
if not queries:
return []
Expand All @@ -98,7 +101,7 @@ def _gather_queries(self):
is_select = query['statement'].strip().lower().startswith('select')
params = ''
try:
params = json_encoder.encode(query['parameters'])
params = json_encoder(query['parameters'])
except TypeError:
return 'Unable to serialize parameters of the query'

Expand Down