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

Bug (?): Filter validation #445

Closed
drmclean opened this issue May 27, 2015 · 1 comment
Closed

Bug (?): Filter validation #445

drmclean opened this issue May 27, 2015 · 1 comment
Labels

Comments

@drmclean
Copy link

When attemping to filter a resource using a column that doesn't exist server returns error 500 rather than a useful message.

example:

RESOURCES

 class AnomalyType(db.Model):
        id                  = db.Column(db.Integer, primary_key=True)
        name                = db.Column(db.String(32))
        version             = db.Column(db.Integer)
        description         = db.Column(db.String(1024))
        metrics             = db.Column(db.String(1024))
        version_comment     = db.Column(db.String(1024))
        min_gap_length      = db.Column(db.Integer)
        min_duration        = db.Column(db.Integer)
        min_data_points     = db.Column(db.Integer)
        gap_anomaly         = db.Column(db.Boolean)
        serial_number       = db.Column(db.String)

# Relationships
        anomalies           = db.relationship('Anomaly',backref=db.backref('anomaly_type',lazy='joined'),lazy='dynamic')

# META DATA
        created_at          = db.Column(db.DateTime)
        modified_at         = db.Column(db.DateTime)
        created_by          = db.Column(db.String(64))

QUERY

url = 'http://<myurl>/v1/anomaly_types'

filters = [dict(name='status', op='eq', val='live')]
params = dict(q=json.dumps(dict(filters=filters)))

r = requests.get(url=url, params=params, headers=headers)
print r.status_code
print r.text

RESPONSE

    500
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
    <title>500 Internal Server Error</title>
    <h1>Internal Server Error</h1>
    <p>The server encountered an internal error and was unable to complete your request.  Either the     server is overloaded or there is an error in the application.</p>

ERROR ON SERVER

ERROR:app:Exception on /v1/anomaly_types [GET]

Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1477, in full_dispatch_request
      rv = self.handle_user_exception(e)
  File "/usr/local/lib/python2.7/dist-packages/flask_cors/__init__.py", line 279, in wrapped_function
     return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1381, in handle_user_exception
     reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1475, in full_dispatch_request
     rv = self.dispatch_request()
   File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1461, in dispatch_request
    (**req.view_args)
   File "/usr/local/lib/python2.7/dist-packages/flask_restless/views.py", line 157, in decorator
     return func(*args, **kw)
   File "/usr/local/lib/python2.7/dist-packages/mimerender.py", line 229, in wrapper
     result = target(*args, **kwargs)
   File "/usr/local/lib/python2.7/dist-packages/flask/views.py", line 84, in view
     return self.dispatch_request(*args, **kwargs)
   File "/usr/local/lib/python2.7/dist-packages/flask/views.py", line 149, in dispatch_request
     return meth(*args, **kwargs)
   File "/usr/local/lib/python2.7/dist-packages/flask_restless/views.py", line 189, in wrapped
     return func(*args, **kw)
   File "/usr/local/lib/python2.7/dist-packages/flask_restless/views.py", line 1239, in get
     return self._search()
   File "/usr/local/lib/python2.7/dist-packages/flask_restless/views.py", line 1164, in _search
     result = strings_to_dates(query_model, to_convert)
   File "/usr/local/lib/python2.7/dist-packages/flask_restless/helpers.py", line 563, in strings_to_dates
     if is_date_field(model, fieldname) and value is not None:
   File "/usr/local/lib/python2.7/dist-packages/flask_restless/helpers.py", line 185, in is_date_field
     fieldtype = get_field_type(model, fieldname)
   File "/usr/local/lib/python2.7/dist-packages/flask_restless/helpers.py", line 163, in get_field_type
     field = getattr(model, fieldname)

 AttributeError: type object 'AnomalyType' has no attribute 'status'

Perhaps a check before filtering to confirm that the filters are real columns before proceeding and a return such as:

response.status_code : 400
response.text : {"error" : " is not a validate column to filter"}

for example?

@jfinkels jfinkels added the bug label Feb 16, 2016
@jfinkels
Copy link
Owner

I think this is fixed in the development version. See commit d79b45f.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants