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:
            return
        ct = 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

查看回复