Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何加载所有sqlalchemy orm实例属性,以便安全地删除它们_Python_Sqlalchemy - Fatal编程技术网

Python 如何加载所有sqlalchemy orm实例属性,以便安全地删除它们

Python 如何加载所有sqlalchemy orm实例属性,以便安全地删除它们,python,sqlalchemy,Python,Sqlalchemy,在sqlalchemy中,是否可以强制加载我的orm实例的所有属性,以便可以安全地删除 我要处理的具体案例是我写了一个装饰师 def auto_session(func): """ Decorate a function that takes a 'session' keyword argument. If a session is provided, this decorator does nothing; if no session is provided,

在sqlalchemy中,是否可以强制加载我的orm实例的所有属性,以便可以安全地删除

我要处理的具体案例是我写了一个装饰师

def auto_session(func):
    """
    Decorate a function that takes a 'session' keyword argument. If a
    session is provided, this decorator does nothing; if no session is
    provided, one will be created an committed.

    Before closing the auto-session, ``expunge_all()`` is called. Be aware
    that this means subsequent modifications to these object instances will
    NOT be reflected in the database.
    """

    def inner(dbi, *args, **kwargs):
        if "session" in kwargs:
            return func(*args, **kwargs)
        else:
            kwargs["session"] = Session()
            ret = func(*args, **kwargs)
            kwargs["session"].commit()
            kwargs["session"].expunge_all()
            kwargs["session"].close()
            return ret

    return inner
这导致错误
实例未绑定到会话;属性刷新操作无法继续
。据我所知,这是由延迟加载的属性或关系引起的,调用方将无法访问这些属性或关系,因为它们在decorator中被删除

我可以想象解决这个问题的一种方法是在调用
expunge_all()
之前强制加载。在炼金术中有没有办法做到这一点