У меня вот такая ошибка.
AttributeError: Neither ‘count’ object nor ‘Comparator’ object has an attribute ‘_autoflush’Появляется она когда я использую sqlalchemy.func в запросах, от обьектов db.Query <- Этот обьект появляется с пакета Flask-Alschemy. Если использую db.session.query, работает нормально. Хочу использовать db.Query так как добавляет paginate.
Вот так выглядит запросы:
s = db.Query(UserModel, func.count(FriendModel.friend_id)).select_from(UserModel).outerjoin(FriendModel, and_(UserModel.id==FriendModel.user_id)).group_by(FriendModel.user_id).subquery() paginator = db.Query(FriendModel).outerjoin(s, FriendModel.user_id==s.c.id).paginate(page, per_page)
Лог ошибки.
File "/home/viktor/venvs/flask_test_task/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__ return self.wsgi_app(environ, start_response) File "/home/viktor/venvs/flask_test_task/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app response = self.make_response(self.handle_exception(e)) File "/home/viktor/venvs/flask_test_task/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception reraise(exc_type, exc_value, tb) File "/home/viktor/venvs/flask_test_task/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app response = self.full_dispatch_request() File "/home/viktor/venvs/flask_test_task/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request rv = self.handle_user_exception(e) File "/home/viktor/venvs/flask_test_task/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception reraise(exc_type, exc_value, tb) File "/home/viktor/venvs/flask_test_task/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request rv = self.dispatch_request() File "/home/viktor/venvs/flask_test_task/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request return self.view_functions[rule.endpoint](**req.view_args) File "/home/viktor/venvs/flask_test_task/lib/python2.7/site-packages/flask_classy.py", line 200, in proxy response = view(**request.view_args) File "/home/viktor/venvs/flask_test_task/lib/python2.7/site-packages/flask_login.py", line 758, in decorated_view return func(*args, **kwargs) File "/home/viktor/github/flask_test_task/core/views/profile.py", line 53, in list users, pagination = current_user.get_users(page, 4) File "/home/viktor/github/flask_test_task/core/model/user.py", line 65, in get_users paginator = db.Query(FriendModel).outerjoin(s, FriendModel.user_id==s.c.id).paginate(page, per_page) File "/home/viktor/venvs/flask_test_task/lib/python2.7/site-packages/flask_sqlalchemy/__init__.py", line 405, in paginate items = self.limit(per_page).offset((page - 1) * per_page).all() File "/home/viktor/venvs/flask_test_task/lib/python2.7/site-packages/sqlalchemy/orm/query.py", line 2300, in all return list(self) File "/home/viktor/venvs/flask_test_task/lib/python2.7/site-packages/sqlalchemy/orm/query.py", line 2411, in __iter__ self.session._autoflush() AttributeError: 'NoneType' object has no attribute '_autoflush
Спасибо.