我在尝试对JSONB对象中包含的数据执行flask-restless api查询时遇到问题。我猜它是因为基础查询不知道如何投射数据字段,所以它不知道如何正确生成查询,但是我是不确定。
执行ajax搜索时运行的查询:
var result = this._tsUserService.deleteTsUser(params)
.then(
r => {
this.result.result = r.result;
this.result.messages = r.messages;
console.log('RES: ' + this.result.result);
}
);
这是我运行查询时获得的回溯。
http://192.168.163.129:1080/api/subscribers?page=1&results_per_page=10&q={"filters":[{"name":"data","op":"has","val":{"name":"full_name","op":"eq","val":"%Steve%"}}],"order_by":[{"field":"created","direction":"asc"}]}
API代码:
2016-12-29 22:26:33,068 - app - ERROR - mapper
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/flask_restless/views.py", line 1172, in _search
result = search(self.session, self.model, search_params)
File "/usr/local/lib/python2.7/dist-packages/flask_restless/search.py", line 587, in search
query = create_query(session, model, search_params, _ignore_order_by)
File "/usr/local/lib/python2.7/dist-packages/flask_restless/search.py", line 549, in create_query
_ignore_order_by)
File "/usr/local/lib/python2.7/dist-packages/flask_restless/search.py", line 480, in create_query
filters = [create_filt(model, filt) for filt in search_params.filters]
File "/usr/local/lib/python2.7/dist-packages/flask_restless/search.py", line 438, in _create_filter
return create_op(model, fname, filt.operator, val, relation)
File "/usr/local/lib/python2.7/dist-packages/flask_restless/search.py", line 411, in _create_operation
return opfunc(field, argument, fieldname)
File "/usr/local/lib/python2.7/dist-packages/flask_restless/search.py", line 106, in <lambda>
'has': lambda f, a, fn: f.has(_sub_operator(f, a, fn)),
File "/usr/local/lib/python2.7/dist-packages/flask_restless/search.py", line 37, in _sub_operator
submodel = model.property.mapper.class_
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/util/langhelpers.py", line 833, in __getattr__
return self._fallback_getattr(key)
File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/util/langhelpers.py", line 811, in _fallback_getattr
raise AttributeError(key)
AttributeError: mapper
预处理器是一个简单的身份验证处理器。
知道如何正确格式化过滤器以过滤JSONB postgres字段吗?
答案 0 :(得分:2)
在这一点上的答案是,你不能用烧瓶 - 不安。
我对flask-restless进行了一些修改,以拆分特殊格式的查询字符串并正确地为jsonb强制转换查询。有点痛苦,可能无法扩展。
它标记为增强烧瓶 - 不安定的git。