librelist archives

« back to archive

[flask] query for date on Flask-Restless / SQLAlchemy / Postgres

[flask] query for date on Flask-Restless / SQLAlchemy / Postgres

From:
Florian Baumgartner
Date:
2013-08-19 @ 15:01
I'm encountering a problem where I try to query an flask-restless api
providing a date. Googling around this could be related to how the query is
built against postgres, however I'm not sure what I need to change to make
this succeed. Any help appreciated.


The script that queries the api uses this filter:

{'q': '{"filters": [{"name": "timestamp", "val": "2013-08-19%", "op":
"like"}]}'}


Output from the server:



--------------------------------------------------------------------------------
ERROR in views

[/home/fbaumgar/src/castello/lib/python2.7/site-packages/flask_restless/views.py:859]:
(InternalError) current transaction is aborted, commands ignored until end
of transaction block

--------------------------------------------------------------------------------
Traceback (most recent call last):
  File
"/home/fbaumgar/src/castello/lib/python2.7/site-packages/flask_restless/views.py",
line 853, in _search
    result = search(self.session, self.model, search_params)
  File

"/home/fbaumgar/src/castello/lib/python2.7/site-packages/flask_restless/search.py",
line 482, in search
    return query.all()
  File
"/home/fbaumgar/src/castello/lib/python2.7/site-packages/sqlalchemy/orm/query.py",
line 2104, in all
    return list(self)
  File
"/home/fbaumgar/src/castello/lib/python2.7/site-packages/sqlalchemy/orm/query.py",
line 2216, in __iter__
    return self._execute_and_instances(context)
  File
"/home/fbaumgar/src/castello/lib/python2.7/site-packages/sqlalchemy/orm/query.py",
line 2231, in _execute_and_instances
    result = conn.execute(querycontext.statement, self._params)
  File

"/home/fbaumgar/src/castello/lib/python2.7/site-packages/sqlalchemy/engine/base.py",
line 662, in execute
    params)
  File

"/home/fbaumgar/src/castello/lib/python2.7/site-packages/sqlalchemy/engine/base.py",
line 761, in _execute_clauseelement
    compiled_sql, distilled_params
  File

"/home/fbaumgar/src/castello/lib/python2.7/site-packages/sqlalchemy/engine/base.py",
line 874, in _execute_context
    context)
  File

"/home/fbaumgar/src/castello/lib/python2.7/site-packages/sqlalchemy/engine/base.py",
line 1024, in _handle_dbapi_exception
    exc_info
  File

"/home/fbaumgar/src/castello/lib/python2.7/site-packages/sqlalchemy/util/compat.py",
line 163, in raise_from_cause
    reraise(type(exception), exception, tb=exc_tb)
  File

"/home/fbaumgar/src/castello/lib/python2.7/site-packages/sqlalchemy/engine/base.py",
line 867, in _execute_context
    context)
  File

"/home/fbaumgar/src/castello/lib/python2.7/site-packages/sqlalchemy/engine/default.py",
line 324, in do_execute
    cursor.execute(statement, parameters)
InternalError: (InternalError) current transaction is aborted, commands
ignored until end of transaction block
 'SELECT state_nat_dynamic.id AS state_nat_dynamic_id,
state_nat_dynamic.location_code AS state_nat_dynamic_location_code,
state_nat_dynamic.type AS state_nat_dynamic_type, state_nat_dynamic.switch
AS state_nat_dynamic_switch, state_nat_dynamic.label AS
state_nat_dynamic_label, state_nat_dynamic.acl AS state_nat_dynamic_acl,
state_nat_dynamic.protocol AS state_nat_dynamic_protocol,
state_nat_dynamic.inside_global_ip AS state_nat_dynamic_inside_global_ip,
state_nat_dynamic.inside_global_port AS
state_nat_dynamic_inside_global_port, state_nat_dynamic.inside_local_ip AS
state_nat_dynamic_inside_local_ip, state_nat_dynamic.inside_local_port AS
state_nat_dynamic_inside_local_port, state_nat_dynamic.outside_global_ip AS
state_nat_dynamic_outside_global_ip, state_nat_dynamic.outside_global_port
AS state_nat_dynamic_outside_global_port, state_nat_dynamic.hostname AS
state_nat_dynamic_hostname, state_nat_dynamic.timestamp AS
state_nat_dynamic_timestamp \nFROM state_nat_dynamic \nWHERE
state_nat_dynamic.timestamp LIKE %(timestamp_1)s' {'timestamp_1':
u'2013-08-19%'}
127.0.0.1 - - [19/Aug/2013 16:53:43] "GET

/net/v1/state_nat_dynamic?q=%7B%22filters%22%3A+%5B%7B%22name%22%3A+%22timestamp%22%2C+%22val%22%3A+%222013-08-19%25%22%2C+%22op%22%3A+%22like%22%7D%5D%7D
HTTP/1.1" 400 -