Repository: django-wiki/django-wiki

Issue:
Previewing a non-int value in querystring generates TypeError
```
Traceback (most recent call last):

  File "/venv/lib/python3.4/site-packages/django/core/handlers/base.py", line 112, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)

  File "/venv/lib/python3.4/site-packages/django/views/generic/base.py", line 69, in view
    return self.dispatch(request, *args, **kwargs)

  File "/venv/lib/python3.4/site-packages/django/utils/decorators.py", line 29, in _wrapper
    return bound_func(*args, **kwargs)

  File "./wiki/decorators.py", line 182, in wrapper
    return func(request, article, *args, **kwargs)

  File "/venv/lib/python3.4/site-packages/django/utils/decorators.py", line 25, in bound_func
    return func(self, *args2, **kwargs2)

  File "./wiki/views/article.py", line 739, in dispatch
    id=revision_id)

  File "/venv/lib/python3.4/site-packages/django/shortcuts/__init__.py", line 113, in get_object_or_404
    return queryset.get(*args, **kwargs)

  File "/venv/lib/python3.4/site-packages/django/db/models/query.py", line 301, in get
    clone = self.filter(*args, **kwargs)

  File "/venv/lib/python3.4/site-packages/django/db/models/query.py", line 593, in filter
    return self._filter_or_exclude(False, *args, **kwargs)

  File "/venv/lib/python3.4/site-packages/django/db/models/query.py", line 611, in _filter_or_exclude
    clone.query.add_q(Q(*args, **kwargs))

  File "/venv/lib/python3.4/site-packages/django/db/models/sql/query.py", line 1204, in add_q
    clause = self._add_q(where_part, used_aliases)

  File "/venv/lib/python3.4/site-packages/django/db/models/sql/query.py", line 1240, in _add_q
    current_negated=current_negated)

  File "/venv/lib/python3.4/site-packages/django/db/models/sql/query.py", line 1131, in build_filter
    clause.add(constraint, AND)

  File "/venv/lib/python3.4/site-packages/django/utils/tree.py", line 104, in add
    data = self._prepare_data(data)

  File "/venv/lib/python3.4/site-packages/django/db/models/sql/where.py", line 79, in _prepare_data
    value = obj.prepare(lookup_type, value)

  File "/venv/lib/python3.4/site-packages/django/db/models/sql/where.py", line 352, in prepare
    return self.field.get_prep_lookup(lookup_type, value)

  File "/venv/lib/python3.4/site-packages/django/db/models/fields/__init__.py", line 369, in get_prep_lookup
    return self.get_prep_value(value)

  File "/venv/lib/python3.4/site-packages/django/db/models/fields/__init__.py", line 613, in get_prep_value
    return int(value)

ValueError: invalid literal for int() with base 10: '10--'


<WSGIRequest
path:/_revision/preview/1/,
GET:<QueryDict: {'r': ['10--']}>,
POST:<QueryDict: {}>,
```



Discussion:

Resolving patch:
diff --git a/wiki/views/article.py b/wiki/views/article.py
--- a/wiki/views/article.py
+++ b/wiki/views/article.py
@@ -748,10 +748,17 @@ def dispatch(self, request, article, *args, **kwargs):
         self.content = None
         self.preview = False
         if revision_id:
+            try:
+                revision_id = int(revision_id)
+            except ValueError:
+                # ValueError only happens because someone put garbage in the
+                # querystring
+                raise Http404()
             self.revision = get_object_or_404(
                 models.ArticleRevision,
                 article=article,
-                id=revision_id)
+                id=revision_id
+            )
         else:
             self.revision = None
         return super(Preview, self).dispatch(request, article, *args, **kwargs)


Test patch: