-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Request Line is too large (400) sometimes #347
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
5e85b23
Use prefix for patterns
nuklea f390260
Use POST instead GET, cuz GET is limited
nuklea e3426e3
Comment back
nuklea a698a80
Query duration column centered
nuklea 92e2dc9
Replace spaces to tabs
nuklea 918519f
Form for SQL validation
nuklea e85dfe8
Render form insted hidden_fields
nuklea 3d0467d
Got rid of the circular imports
nuklea 4c1c4f7
Merge branch 'master' of https://github.com/django-debug-toolbar/djan…
nuklea 702f574
Fix tests for Django 1.3
nuklea f386dd0
Merge branch 'master' of https://github.com/django-debug-toolbar/djan…
nuklea f6b515f
Add myself to AUTHORS
nuklea File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
from django import forms | ||
from django.conf import settings | ||
from django.core.exceptions import ValidationError | ||
from django.utils.functional import cached_property | ||
|
||
try: | ||
import json | ||
except ImportError: | ||
from django.utils import simplejson as json | ||
|
||
try: | ||
from hashlib import sha1 | ||
except ImportError: | ||
from django.utils.hashcompat import sha_constructor as sha1 | ||
|
||
from debug_toolbar.utils.compat.db import connections | ||
|
||
|
||
class SQLSelectForm(forms.Form): | ||
""" | ||
Validate params | ||
|
||
sql: urlencoded sql with positional arguments | ||
params: JSON encoded parameter values | ||
duration: time for SQL to execute passed in from toolbar just for redisplay | ||
hash: the hash of (secret + sql + params) for tamper checking | ||
""" | ||
sql = forms.CharField() | ||
params = forms.CharField() | ||
alias = forms.CharField(required=False, initial='default') | ||
duration = forms.FloatField() | ||
hash = forms.CharField() | ||
|
||
def __init__(self, *args, **kwargs): | ||
initial = kwargs.get('initial', None) | ||
|
||
if initial is not None: | ||
initial['hash'] = self.make_hash(initial) | ||
|
||
super(SQLSelectForm, self).__init__(*args, **kwargs) | ||
|
||
for name in self.fields: | ||
self.fields[name].widget = forms.HiddenInput() | ||
|
||
def clean_sql(self): | ||
value = self.cleaned_data['sql'] | ||
|
||
if not value.lower().strip().startswith('select'): | ||
raise ValidationError("Only 'select' queries are allowed.") | ||
|
||
return value | ||
|
||
def clean_params(self): | ||
value = self.cleaned_data['params'] | ||
|
||
try: | ||
return json.loads(value) | ||
except ValueError: | ||
raise ValidationError('Is not valid JSON') | ||
|
||
def clean_alias(self): | ||
value = self.cleaned_data['alias'] | ||
|
||
if value not in connections: | ||
raise ValidationError("Database alias '%s' not found" % value) | ||
|
||
return value | ||
|
||
def clean_hash(self): | ||
hash = self.cleaned_data['hash'] | ||
|
||
if hash != self.make_hash(self.data): | ||
raise ValidationError('Tamper alert') | ||
|
||
return hash | ||
|
||
def reformat_sql(self): | ||
from debug_toolbar.panels.sql import reformat_sql | ||
sql, params = self.cleaned_data['sql'], self.cleaned_data['params'] | ||
return reformat_sql(self.cursor.db.ops.last_executed_query(self.cursor, sql, params)) | ||
|
||
def make_hash(self, data): | ||
params = settings.SECRET_KEY + data['sql'] + data['params'] | ||
return sha1(params).hexdigest() | ||
|
||
@property | ||
def connection(self): | ||
return connections[self.cleaned_data['alias']] | ||
|
||
@cached_property | ||
def cursor(self): | ||
return self.connection.cursor() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,13 +41,21 @@ | |
{{ query.duration|floatformat:"2" }} | ||
</td> | ||
<td class="actions"> | ||
|
||
{% if query.params %} | ||
{% if query.is_select %} | ||
<a class="remoteCall" href="/__debug__/sql_select/?sql={{ query.raw_sql|urlencode }}&params={{ query.params|urlencode }}&duration={{ query.duration|floatformat:"2"|urlencode }}&hash={{ query.hash }}&alias={{ query.alias|urlencode }}">Sel</a> | ||
<a class="remoteCall" href="/__debug__/sql_explain/?sql={{ query.raw_sql|urlencode }}&params={{ query.params|urlencode }}&duration={{ query.duration|floatformat:"2"|urlencode }}&hash={{ query.hash }}&alias={{ query.alias|urlencode }}">Expl</a> | ||
{% ifequal query.engine 'mysql' %} | ||
<a class="remoteCall" href="/__debug__/sql_profile/?sql={{ query.raw_sql|urlencode }}&params={{ query.params|urlencode }}&duration={{ query.duration|floatformat:"2"|urlencode }}&hash={{ query.hash }}&alias={{ query.alias|urlencode }}">Prof</a> | ||
{% endifequal %} | ||
<form method="post"> | ||
{% for field in query.form.hidden_fields %} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why only the hidden fields? I think |
||
{{ field }} | ||
{% endfor %} | ||
|
||
<button formaction="/__debug__/sql_select/" class="remoteCall">Sel</button> | ||
<button formaction="/__debug__/sql_explain/" class="remoteCall">Expl</button> | ||
|
||
{% ifequal query.engine 'mysql' %} | ||
<button formaction="/__debug__/sql_profile/" class="remoteCall">Prof</button> | ||
{% endifequal %} | ||
</form> | ||
{% endif %} | ||
{% endif %} | ||
</td> | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's move this to a third module, e.g.
debug_toolbar.utils
or something match.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move what?
reformat_sql
function?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jezdez please, be exactly :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, the
reformat_sql
function so that the import can be moved at the top of the file. I assume you put the import here to prevent a circular import.