[sqlalchemy] Do I need to explicitly close each Session instance in a scoped_session context after use?

2017-08-06 Thread Jinghui Niu
I'm using Sqlite as backend, which doesn't use any connection pools. In my case, I don't know if there is any negative consequences to just let Python garbage collect each Session instance after use? Especially under a multi-threading context. Could someone point out any risks not closing them

Re: [sqlalchemy] avoid setting attribute on init and or.reconstructor

2017-08-06 Thread Shane Carey
Hey Mike, I can expand my example. I have an orm mapped attribute like this class Obj(Base): _evaluator = Column(String) def __init__(self, **kwargs): super().__init__(**kwargs) self._eval_func = eval(self._evaluator) @orm.reconstructor def init_on_load(self):

[sqlalchemy] Why is this pattern discouraged in SQLAlchemy?

2017-08-06 Thread Jinghui Niu
When reading the official SQLAlchemy documentation, I found the example below: ### this is the **wrong way to do it** ### class ThingOne(object): def go(self): session = Session() try: session.query(FooBar).update({"x": 5}) session.commit()

Re: [sqlalchemy] avoid setting attribute on init and or.reconstructor

2017-08-06 Thread Mike Bayer
On Aug 6, 2017 1:33 PM, "Shane Carey" wrote: Hey Mike, I can expand my example. I have an orm mapped attribute like this class Obj(Base): _evaluator = Column(String) def __init__(self, **kwargs): super().__init__(**kwargs) self._eval_func =

Re: [sqlalchemy] Why is this pattern discouraged in SQLAlchemy?

2017-08-06 Thread Mike Bayer
On Aug 6, 2017 8:11 PM, "Jinghui Niu" wrote: When reading the official SQLAlchemy documentation, I found the example below: ### this is the **wrong way to do it** ### class ThingOne(object): def go(self): session = Session() try: