sqlalchemy, postgresql and relationship stuck in “idle in transaction”

后端 未结 2 671
梦如初夏
梦如初夏 2021-02-05 22:06

I have a problem related to sqlalchemy and postgresql.

class Profile(Base):
  ...

  roles = relationship(\'Role\', secondary=role_profiles,
                             


        
2条回答
  •  无人共我
    2021-02-05 22:53

    SQLA by default always operates in a transaction (some info here). In a web context most frameworks would handle committing this transaction for you at the end of the request (e.g. pyramid_tm). If you're not using a framework, or this is another type of application, you'll want to commit or rollback when you're finished, or at an appropriate point.

    It may be possible to configure SQLA such that it doesn't automatically start a transaction but as far as I can see it's not how it is intended to be used so you'll probably have better luck not trying to fight it :).

提交回复
热议问题