Skip to content

Commit

Permalink
Merge pull request jfinkels#299 from mjfroehlich/null_comparison_erro…
Browse files Browse the repository at this point in the history
…r_message

Show error message if search query tests for NULL using comparison operators
  • Loading branch information
jfinkels committed Jul 16, 2014
2 parents 3f066c2 + 7414cdd commit 74304d1
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion flask_restless/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def create_api_blueprint(self, model, methods=READONLY_METHODS,
post_form_preprocessor=None,
preprocessors=None, postprocessors=None,
primary_key=None):
"""Creates an returns a ReSTful API interface as a blueprint, but does
"""Creates and returns a ReSTful API interface as a blueprint, but does
not register it on any :class:`flask.Flask` application.
The endpoints for the API for ``model`` will be available at
Expand Down
4 changes: 3 additions & 1 deletion flask_restless/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,9 @@ def _create_operation(model, fieldname, operator, argument, relation=None):
if numargs == 1:
return opfunc(field)
if argument is None:
raise TypeError
msg = ('To compare a value to NULL, use the is_null/is_not_null '
'operators.')
raise TypeError(msg)
if numargs == 2:
return opfunc(field, argument)
return opfunc(field, argument, fieldname)
Expand Down
2 changes: 2 additions & 0 deletions tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ def test_operators(self):
d = dict(filters=[dict(name='birth_date', op='is_not_null')])
result = search(self.session, self.Person, d)
assert result.count() == 1
d = dict(filters=[dict(name='birth_date', op='eq', val=None)])
assert_raises(TypeError, search, self.session, self.Person, d)

def test_desc_and_asc(self):
"""Tests for the ``"desc"`` and ``"asc"`` operators."""
Expand Down

0 comments on commit 74304d1

Please sign in to comment.