'AttributeError: __aenter__

I'm trying to make a bulk update in my database. Using aiohtpp + sqlachemy. I'm getting a error

    async with sess.begin():
AttributeError: __aenter__

with this code:

  async def update_itens_by_bulk(self) -> Optional[int]:
    sess = Session(self._engine)

    async with sess.begin():
        sess.query(table_order_item).filter(table_order_item.c.id.in_(ids)).update(
            {
                table_order_item.c.store_id: case(
                    payload,
                    value=table_order_item.c.id,
                )
            },
            synchronize_session=False,
        )
        await sess.commit()


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source