"Ian Kelly" <[email protected]> wrote in message
news:calwzidnf3obe0enf3xthlj5a40k8hxvthveipecq8+34zxy...@mail.gmail.com...
> On Tue, Jul 9, 2013 at 10:07 AM, Ethan Furman <[email protected]> wrote:
>> You could also do it like this:
>>
>> def updating(self):
>> self.transaction_active = True
>> return self
>
> Yes, that would be simpler. I was all set to point out why this
> doesn't work, and then I noticed that the location of the
> "transaction_active" attribute is not consistent in the original code.
> The DbSession class places it on self, and then the example usage
> places it on the connection object (which I had based my version on).
> Since that seems to be a source of confusion, it demonstrates another
> reason why factoring this out is a good thing.
You had me worried there for a moment, as that is obviously an error.
Then I checked my actual code, and I find that I mis-transcribed it. It
actually looks like this -
with db_session as conn:
db_session.transaction_active = True
conn.cur.execute(...)
I am still not quite sure what your objection is to this. It feels
straightforward to me.
Here is one possible answer. Whenever I want to commit a transaction I have
to add the extra line. There is a danger that I could mis-spell
'transaction_active', in which case it would not raise an error, but would
not commit the transaction, which could be a hard-to-trace bug. Using your
approach, if I mis-spelled 'db_session.connect()', it would immediately
raise an error.
Is that your concern, or are there other issues?
Frank
--
http://mail.python.org/mailman/listinfo/python-list