- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
最近我遇到了 SQLAlchemy InvalidRequestError。错误日志显示:
InvalidRequestError: Transaction <sqlalchemy.orm.session.SessionTransaction object at
0x106830dd0> is not on the active transaction list
什么情况下会出现这个错误???
-----编辑----
# the following two line actually in my decorator
s = Session()
s.add(model1)
# refer to <http://techspot.zzzeek.org/2012/01/11/django-style-database-routers-in-sqlalchemy/>
s2 = Session().using_bind('master')
model2 = s2.query(Model2).with_lockmode('update').get(1)
model2.somecolumn = 'new'
s2.commit()
引发此异常
-----编辑2-----
s = Session().using_bind('master')
model = Model(user_id=123456)
s.add(model)
s.flush()
# here, raise the exception.
# I add log in get_bind() of RoutingSession. when doing 'flush', the _name is None, and it returns engines['slave'].
#If I use commit() instead of flush(), then it commits successfully
我将 using_bind 方法更改如下,效果很好。
def using_bind(self, name):
self._name = name
return self
上一个路由 session :
class RoutingSession(Session):
_name = None
def get_bind(self, mapper=None, clause=None):
logger.info(self._name)
if self._name:
return engines[self._name]
elif self._flushing:
logger.info('master')
return engines['master']
else:
logger.info('slave')
return engines['slave']
def using_bind(self, name):
s = RoutingSession()
vars(s).update(vars(self))
s._name = name
return s
最佳答案
这是一个永远不应该发生的内部断言。如果您可能不正确地以并发方式使用 session ,或者操纵其内部结构,那么至少没有完整的堆栈跟踪就无法回答这个问题。我只能显示在操作与 Session 对象相关的私有(private)方法或状态时引发的异常。
这是:
from sqlalchemy.orm import Session
s = Session()
s2 = Session()
t = s.transaction
t2 = s2.transaction
s2.transaction = t # nonsensical assignment of the SessionTransaction
# from one Session to also be referred to by another,
# corrupts the transaction chain by leaving out "t2".
# ".transaction" should never be assigned to on the outside
t2.rollback() # triggers the assertion case
基本上,上述情况永远不会发生,因为您不应该分配给“.transaction”。这是一个只读属性。
关于mysql - SQLAlchemy InvalidRequestError('Transaction XXX is not on the active transaction list) 是如何发生的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13968854/
我的代码是从别人那里复制的,代码的目的是测试AzureOpenai API。但是我遇到了一些错误。。输出是这样的。我已经检查了我的终结点网站,但结果是网站中的{“Error”:{“code”:“404
将客户数据和 token 发送回 Stripe 的服务器时似乎存在问题。我目前正在使用测试 api 来进行虚拟交易。但是,我却无缘无故地过不了这一关。我已尝试一切方法来修复此错误。我将在下面发布代码和
我在单独的包中有 3 个文件,如下所示: -- base | - class BaseDb(db.Model) | -- pkg1 | - class A(BaseDb) | -- pkg2 |
我已经实现了Stripe来处理我网站上的订阅。一切都工作正常,除非涉及取消订阅。 这是我的 Controller : Stripe.api_key = Rails.configuration.stri
我从其他人那里复制了代码,代码的目的是测试AzureOpenai API。但是我遇到了一些错误。 `from langchain.llms import AzureOpenAI import os i
我很可能在这里缺少一些基本概念,但我尝试创建一些类似简单的代码审查应用程序的东西,并在设计数据库架构时尝试遵循此文档: http://flask-sqlalchemy.pocoo.org/2.1/mo
http://jsfiddle.net/e8wjyb35/ 我的 Controller : class ChargesController params[:stripeToken], :
我试图同时从数据库提交和查询结果,但我遇到了这个错误。 sqlalchemy.exc.InvalidRequestError: This session is in 'committed' state
我正在构建一个应用程序(基于在线资源)。您可以注册或使用设备登录。然后,您可以购买产品。或者制作您自己的 list 并销售您的产品。 我正在整合 Stripe。当我创建 Charge 时,我在控制台中
将我的模型移动到它们自己的模块会导致 InvalidRequestError.. 这似乎与数据库 session 以及我在模型模块中导入数据库的方式有关。 我试图将这个问题减少到所需的最少代码量。首先
尝试访问 OpenAPI 示例 - Explain code但它显示错误为 - InvalidRequestError: Engine not found enter code response =
尝试访问 OpenAPI 示例 - Explain code但它显示错误为 - InvalidRequestError: Engine not found enter code response =
我正在为我的 iOS 应用程序构建后端,并选择使用 Flask 框架。 对于数据库部分,我使用 flask-sqlalchemy 连接我的 mysql 数据库。 当我将所有测试代码放在一个单个文件中时
我正在尝试使用 SQLAlchemy 自动映射扩展为现有数据库生成 ORM,并收到 InvalidRequestError 异常(“实例无法刷新 - 它不是持久的并且不包含完整的主键。”)我尝试插入一
我正在一个名为 foodsy 的电子商务市场上工作。我正在使用 stripe connect为目的。连接帐户是使用 stripe-connect-omniauth 创建的. Foodsy 有几个客户。
我正在使用 Flask 创建一个论坛项目,并使用 Flask-SQLAlchemy 管理所有用户、线程、帖子等。但是,我发现当我尝试执行 x(例如编辑帖子)时,如果我尝试执行其他任何操作(例如删除帖子
我正在使用 SQLAlchemy 核心(版本 1.13.12)定义两个必须具有一对一 (0..1) 关系的表: things = sa.Table( "things", metadat
如果我将 CapacityMin 类和单元测试类放在同一个 .py 文件中,一切都很好。但是在我将 CapacityMin 类移动到一个单独的文件并运行单元测试后,我得到了这个错误: 需要 SQL 表
我不再收到任何错误,但我知道当我创建一个新用户时,不会写入 stripeToken。 controllers/users/registrations_controller.rb class Users
关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。 这个问题是由于错别字或无法再重现的问题引起的。虽然类似的问题可能是on-topi
我是一名优秀的程序员,十分优秀!