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

Show error message if search query tests for NULL using comparison operators #299

Merged
merged 4 commits into from Jul 16, 2014
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion flask_restless/manager.py
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
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.')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String continuation should start at the same column as the beginning of the string literal on the previous line.

raise TypeError(msg)
if numargs == 2:
return opfunc(field, argument)
return opfunc(field, argument, fieldname)
Expand Down
3 changes: 3 additions & 0 deletions tests/test_search.py
Expand Up @@ -145,6 +145,9 @@ 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)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this blank line.


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