mysql - AttributeError: ’module’ object has no attribute ’MatchType’
问题描述
ct = db.session.query(CIType).filter(CIType.type_name == key).first() or db.session.query(CIType).filter(CIType.type_id == key).first()
线上有时候会报错,暂时找不到原因,有遇到过的么?
2016-08-11 14:27:26,177 ERROR /usr/lib/python2.6/site-packages/flask/app.py 1306 - Exception on /api/v0.1/projects/search-indexer-rafael/product [GET]Traceback (most recent call last): File '/usr/lib/python2.6/site-packages/flask/app.py', line 1687, in wsgi_app response = self.full_dispatch_request() File '/usr/lib/python2.6/site-packages/flask/app.py', line 1360, in full_dispatch_request rv = self.handle_user_exception(e) File '/usr/lib/python2.6/site-packages/flask/app.py', line 1358, in full_dispatch_request rv = self.dispatch_request() File '/usr/lib/python2.6/site-packages/flask/app.py', line 1344, in dispatch_request return self.view_functions[rule.endpoint](**req.view_args) File '/data/webapps/cmdb-api/core/special.py', line 175, in get_project_product product = ProjectManager().get_for_product(project_name) File '/data/webapps/cmdb-api/lib/special/project.py', line 18, in __init__ self.ci_type = CITypeCache.get('project') File '/data/webapps/cmdb-api/models/cmdb.py', line 458, in get ct = db.session.query(CIType).filter( File '/usr/lib64/python2.6/site-packages/sqlalchemy/orm/scoping.py', line 149, in do def do(self, *args, **kwargs): File '/usr/lib64/python2.6/site-packages/sqlalchemy/util/_collections.py', line 903, in __call__ item = dict.get(self, key) File '/usr/lib/python2.6/site-packages/flask_sqlalchemy.py', line 201, in __init__ bind=db.engine, File '/usr/lib/python2.6/site-packages/flask_sqlalchemy.py', line 754, in engine return self.get_engine(self.get_app()) File '/usr/lib/python2.6/site-packages/flask_sqlalchemy.py', line 771, in get_engine return connector.get_engine() File '/usr/lib/python2.6/site-packages/flask_sqlalchemy.py', line 451, in get_engine self._engine = rv = sqlalchemy.create_engine(info, **options) File '/usr/lib64/python2.6/site-packages/sqlalchemy/engine/__init__.py', line 344, in create_engine of 0 indicates no limit; to disable pooling, set ``poolclass`` to File '/usr/lib64/python2.6/site-packages/sqlalchemy/engine/strategies.py', line 50, in create File '/usr/lib64/python2.6/site-packages/sqlalchemy/engine/url.py', line 116, in get_dialect return self.get_dialect().driver File '/usr/lib64/python2.6/site-packages/sqlalchemy/util/langhelpers.py', line 170, in load fn.__func__.__doc__ = doc File '/usr/lib64/python2.6/site-packages/sqlalchemy/dialects/__init__.py', line 33, in _auto_fn try: File '/usr/lib64/python2.6/site-packages/sqlalchemy/dialects/mysql/__init__.py', line 8, in <module> from . import base, mysqldb, oursql, File '/usr/lib64/python2.6/site-packages/sqlalchemy/dialects/mysql/base.py', line 681, in <module> class _MatchType(sqltypes.Float, sqltypes.MatchType):AttributeError: ’module’ object has no attribute ’MatchType’
代码
@special.route('/api/v0.1/projects/<string:project_name>/product', methods=['GET'])def get_project_product(project_name): product = ProjectManager().get_for_product(project_name) return jsonify(product=product)...
goto
class ProjectManager(object): def __init__(self):self.ci_type = CITypeCache.get('project')...
then
class CITypeCache(object): @classmethod def get(cls, key):if key is None: returnct = cache.get('CIType::ID::%s' % key) or cache.get('CIType::Name::%s' % key)if ct is None: ct = db.session.query(CIType).filter(CIType.type_name == key).first() or db.session.query(CIType).filter(CIType.type_id == key).first() if ct is not None:CITypeCache.set(ct)return ct
sqlalchemy 版本:SQLAlchemy-1.0.8-py2.6.egg-info
问题解答
回答1:查看一下sqlalchemy的版本
再检查一下这个路径sqlalchemy.types.MatchType是否存在
翻看一下sql的代码,1.1代码和1.0.8的代码实现都不一样了,升级一下呗
相关文章:
1. php工具箱配置第二个vhost主机时不生效,报错You don’t have permission2. gosts内容是空的3. javascript - 百度echarts图表如何修改4. javascript - 使用百度文本编辑器ueditor不显示样式问题5. mysql5.7就没有官方性质的详细配置文件吗?求大神告知6. html5 - 这种动效是如何做出来的?7. MySQL数据库服务器循环插入执行速度慢8. python - 用urllib抓取网页上的下载链接,目标文件是xls形式,但发现抓下来的xls是空表,里面只有一句报错信息,求帮助。9. javascript - 百度图片切换图片时url会改变,但无刷新,没用hash,IE8也支持,请问是用了什么技术?10. php mysql_query()问题