为了能到远方,脚下的每一步都不能少.|

bitterteaer

园龄:3年8个月粉丝:1关注:0

sqlalchemy -> expire_on_commit

当 expire_on_commit=True 时,commit 之后所有实例都会过期,之后再访问这些过期实例的属性时,SQLAlchemy 会重新去数据库加载实例对应的数据记录。

# SQLAlchemy 源码,非关键内容省略
class Session(_SessionClassMethods):
    """
    Manages persistence operations for ORM-mapped objects.
    The Session's usage paradigm is described at :doc:`/orm/session`.
    """
    ...
    def __init__(
        self,
        bind=None,
        autoflush=True,
        expire_on_commit=True,
        ...
    ):
    """
        :param expire_on_commit:  Defaults to ``True``. When ``True``, all
           instances will be fully expired after each :meth:`~.commit`,
           so that all attribute/object access subsequent to a completed
           transaction will load from the most recent database state.
    """

原文链接: https://youguanxinqing.xyz/archives/147/

本文作者:bitterteaer

本文链接:https://www.cnblogs.com/bitterteaer/p/17840274.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   bitterteaer  阅读(173)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起