You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to use a generator function to avoid doing commit or rollback in every parent service, but I cannot make it work with dependency-injector. And use this:
@contextmanager
def session(self):
s: Session = self.orm_session()
try:
yield s
s.commit()
except Exception as e:
s.rollback()
finally:
s.close()
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have configured a simple fastapi app with 2 services. Dummy and Dummy2. Dummy calls Dummy2 and they all run in same transaction.
Instead of using in Database
I would like to use a generator function to avoid doing commit or rollback in every parent service, but I cannot make it work with dependency-injector. And use this:
I am dealing with this line in Container
db_session = providers.ContextLocalSingleton(db.provided.session.call())
But nothing seems to work. (without generator function works fine)
Any suggestions?
Beta Was this translation helpful? Give feedback.
All reactions