事务内的sqlalchemy postgresql函数调用

事务内的sqlalchemy postgresql函数调用,postgresql,transactions,sqlalchemy,Postgresql,Transactions,Sqlalchemy,我正在尝试为我的PostgreSQL函数编写测试。我很难理解为什么我的PostgreSQL函数什么都不返回 def test_sql_func_get_loc_eft_draft_one(session): test_passed = True # Build up the test environment trans = session.begin() # Add a dummy location record add_dummy_location(

我正在尝试为我的PostgreSQL函数编写测试。我很难理解为什么我的PostgreSQL函数什么都不返回

def test_sql_func_get_loc_eft_draft_one(session):
    test_passed = True

    # Build up the test environment
    trans = session.begin()

    # Add a dummy location record
    add_dummy_location(session)

    # Add a dummy membership record
    add_one_dummy_member(session)

    # Print the membership record we just wrote
    req_query = session.query(models.Membership).\
        filter(models.Membership.home_club == 9999).first()
    print(req_query)

    # Run the test with one record
    t1 = session.query(func.get_dues(9999, '1/1/2014', '1/1/2016')).first()
    print(t1)
    try:
        assert t1[0] == 10.00

    except:
        test_passed = False

    # Break down the test environment
    trans.rollback()

    assert test_passed

当我打印我写的会员记录时,它会正确显示,在“会费”字段中显示10.00。当我尝试使用该函数检索应付款时,返回零,测试失败。我不能在事务中使用PostgreSQL函数调用吗?

您可以在事务中使用函数。获取费用的定义是什么?我发现了错误。添加一个新成员应该触发一个触发器来创建一个成员历史记录,但由于它不是一个延迟约束触发器,所以从未创建过该记录。或者更确切地说,它是一个延迟约束触发器。