Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add DebugToolBarJSONDecoder class for better organization of code
  • Loading branch information
eduzen authored and Eduardo Enriquez committed Mar 14, 2026
commit bc395f0d85d1b5dc8cdd3361ecbb57858c740cf7
26 changes: 26 additions & 0 deletions debug_toolbar/panels/sql/decoders.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import base64
import json


class DebugToolbarJSONDecoder(json.JSONDecoder):
Comment thread
eduzen marked this conversation as resolved.
Outdated
"""Custom JSON decoder that reconstructs binary data during parsing."""

def decode(self, s):
"""Override decode to apply reconstruction after parsing."""
obj = super().decode(s)
return self._reconstruct_params(obj)

def _reconstruct_params(self, params):
"""Reconstruct parameters, handling lists and dicts recursively."""
if isinstance(params, list):
return [self._reconstruct_params(param) for param in params]
elif isinstance(params, dict):
if "__djdt_binary__" in params:
return base64.b64decode(params["__djdt_binary__"])
else:
return {
key: self._reconstruct_params(value)
for key, value in params.items()
}
else:
return params
Comment thread
tim-schilling marked this conversation as resolved.
Outdated
3 changes: 2 additions & 1 deletion debug_toolbar/panels/sql/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from django.utils.functional import cached_property
from django.utils.translation import gettext_lazy as _

from debug_toolbar.panels.sql.decoders import DebugToolbarJSONDecoder
from debug_toolbar.panels.sql.utils import is_select_query, reformat_sql
from debug_toolbar.toolbar import DebugToolbar

Expand Down Expand Up @@ -90,7 +91,7 @@ def clean(self):
def _get_query_params(self):
"""Get reconstructed parameters for the current query"""
query = self.cleaned_data["query"]
return _reconstruct_params(json.loads(query["params"]))
return json.loads(query["params"], cls=DebugToolbarJSONDecoder)

def select(self):
query = self.cleaned_data["query"]
Expand Down