应用程序进程无法使用“...... - 无法继续初始化其他映射程序。”

时间:2018-05-01 20:06:34

标签: python sqlalchemy

我不确定我是应该将其视为一个错误还是我需要解决的问题。

我有一个Flask应用程序,可以同时处理Web请求并启动后端作业的线程。当我连接到DB时,我只是在上面的故障中有一个后端作业结果我定期从中提取数据。它无法映射的表甚至不是我在该数据库中查询的表,但是它的映射失败不仅导致后端作业失败,而且它使SQLAlchemy处于无法从该点映射其他任何东西的状态 - - 包括提供甚至无法访问该数据库的Web请求!

这也只是一个侥幸的问题。我重新启动了我的应用程序和无法映射映射的表格。

有没有办法阻止SQLAlchemy进入“不会映射!”申请中的州?如果它被包含在一个单独的连接中,它就不会那么大,但似乎将它存储在全局空间中,从而完全打破了应用程序的故障点。

编辑: 它终于再来了。这是完整的堆栈:

Traceback (most recent call last):
  File "/home/dmittner/loci2/app/jobs.py", line 506, in start
    result = self.callable(self,**self.parameters)
  File "/home/dmittner/loci2/app/jobs.py", line 467, in job_test
    breakout_property = False
  File "/home/dmittner/loci2/app/api/mod_system/services.py", line 1166, in get_usage
    threshold = summary_threshold
  File "/home/dmittner/loci2/app/api/mod_system/services.py", line 2243, in _get_usage_summary
    'id': result2.regional_region_id,
  File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/orm/attributes.py", line 242, in __get__
    return self.impl.get(instance_state(instance), dict_)
  File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/orm/attributes.py", line 598, in get
    value = state._load_expired(state, passive)
  File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/orm/state.py", line 608, in _load_expired
    self.manager.deferred_scalar_loader(self, toload)
  File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/orm/loading.py", line 844, in load_scalar_attributes
    session.query(mapper),
  File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/orm/session.py", line 1393, in query
    return self._query_cls(entities, self, **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/orm/query.py", line 140, in __init__
    self._set_entities(entities)
  File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/orm/query.py", line 151, in _set_entities
    self._set_entity_selectables(self._entities)
  File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/orm/query.py", line 181, in _set_entity_selectables
    ent.setup_entity(*d[entity])
  File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/orm/query.py", line 3619, in setup_entity
    self._with_polymorphic = ext_info.with_polymorphic_mappers
  File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/util/langhelpers.py", line 767, in __get__
    obj.__dict__[self.__name__] = result = self.fget(obj)
  File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/orm/mapper.py", line 1994, in _with_polymorphic_mappers
    configure_mappers()
  File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/orm/mapper.py", line 3013, in configure_mappers
    mapper._post_configure_properties()
  File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/orm/mapper.py", line 1811, in _post_configure_properties
    prop.init()
  File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/orm/interfaces.py", line 184, in init
    self.do_init()
  File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/orm/relationships.py", line 1655, in do_init
    self._process_dependent_arguments()
  File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/orm/relationships.py", line 1712, in _process_dependent_arguments
    self.target = self.mapper.mapped_table
  File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/util/langhelpers.py", line 767, in __get__
    obj.__dict__[self.__name__] = result = self.fget(obj)
  File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/orm/relationships.py", line 1634, in mapper
    configure=False)
  File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/orm/base.py", line 426, in class_mapper
    raise exc.UnmappedClassError(class_)
sqlalchemy.orm.exc.UnmappedClassError: Class 'sqlalchemy.ext.automap.geo_state_map_data' is not mapped

值得注意的是geo_state表甚至不是我使用的表,但无论如何都是自动化程序正在处理的表。从那时起,我得到原始消息,阻止该过程成功建立任何新连接。

从SQLAlchemy的代码中查看,映射器存储在_mapper_registry全局空间变量中,一旦注册表中的任何映射器出错,任何配置新映射器的尝试都将失败。

0 个答案:

没有答案