Page MenuHomePhorge

D1690.diff
No OneTemporary

D1690.diff

diff --git a/pykolab/auth/ldap/auth_cache.py b/pykolab/auth/ldap/auth_cache.py
--- a/pykolab/auth/ldap/auth_cache.py
+++ b/pykolab/auth/ldap/auth_cache.py
@@ -17,6 +17,7 @@
#
import datetime
+import os
import sqlalchemy
@@ -84,6 +85,11 @@
db = init_db()
+ if db is None:
+ return
+
+ purge_entries()
+
try:
db.query(Entry).filter_by(key=key).delete()
except sqlalchemy.exc.OperationalError:
@@ -102,6 +108,9 @@
db = init_db()
+ if db is None:
+ return None
+
try:
_entries = db.query(Entry).filter_by(key=key).all()
except sqlalchemy.exc.OperationalError:
@@ -121,8 +130,14 @@
def set_entry(key, value):
+ # pylint: disable=global-statement
+ global db
+
db = init_db()
+ if db is None:
+ return
+
try:
_entries = db.query(Entry).filter_by(key=key).all()
except sqlalchemy.exc.OperationalError:
@@ -147,12 +162,18 @@
db.commit()
-def purge_entries(db):
- db.query(Entry).filter(
- Entry.last_change <= (datetime.datetime.now() - datetime.timedelta(1))
- ).delete()
+def purge_entries():
+ # pylint: disable=global-statement
+ global db
- db.commit()
+ try:
+ db.query(Entry).filter(
+ Entry.last_change <= (datetime.datetime.now() - datetime.timedelta(1))
+ ).delete()
+
+ db.commit()
+ except Exception:
+ return
def init_db(reinit=False):
@@ -167,11 +188,13 @@
db_uri = conf.get('ldap', 'auth_cache_uri')
+ if db_uri == "null":
+ return None
+
if db_uri is None:
db_uri = 'sqlite:///%s/auth_cache.db' % (KOLAB_LIB_PATH)
if reinit:
- import os
if os.path.isfile('%s/auth_cache.db' % (KOLAB_LIB_PATH)):
os.unlink('%s/auth_cache.db' % (KOLAB_LIB_PATH))
@@ -181,6 +204,5 @@
Session = sessionmaker(bind=engine)
db = Session()
- purge_entries(db)
return db

File Metadata

Mime Type
text/plain
Expires
Thu, Oct 31, 8:33 AM (8 h, 8 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
10075095
Default Alt Text
D1690.diff (1 KB)

Event Timeline