Revision 2907
Added by Aaron Marcuse-Kubitza over 12 years ago
sql.py | ||
---|---|---|
336 | 336 |
|
337 | 337 |
def is_cached(self, query): return query in self.query_results |
338 | 338 |
|
339 |
def with_autocommit(self, func, autocommit=True):
|
|
339 |
def with_autocommit(self, func): |
|
340 | 340 |
import psycopg2.extensions |
341 |
if autocommit: |
|
342 |
isolation_level = psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT |
|
343 |
else: isolation_level = psycopg2.extensions.ISOLATION_LEVEL_SERIALIZABLE |
|
344 | 341 |
|
345 | 342 |
prev_isolation_level = self.db.isolation_level |
346 |
self.db.set_isolation_level(isolation_level) |
|
343 |
self.db.set_isolation_level( |
|
344 |
psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT) |
|
347 | 345 |
try: return func() |
348 | 346 |
finally: self.db.set_isolation_level(prev_isolation_level) |
349 | 347 |
|
Also available in: Unified diff
sql.py: with_autocommit(): Only allow turning autocommit on, because the opposite is not meaningful and may conflict with the session-global isolation level