aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2008-05-11 20:21:51 +0000
committerRob Austein <sra@hactrn.net>2008-05-11 20:21:51 +0000
commit45f39b2288abeabf7474902de32aeb0537787d15 (patch)
treea8853bd9b0c194a42611177f35d2f061340acba7
parent086ac530c93804c087f23e588df37326278f251e (diff)
Paranoia.
svn path=/rpkid/rpki/sql.py; revision=1763
-rw-r--r--rpkid/rpki/sql.py18
1 files changed, 13 insertions, 5 deletions
diff --git a/rpkid/rpki/sql.py b/rpkid/rpki/sql.py
index 6cab30d9..93cfd644 100644
--- a/rpkid/rpki/sql.py
+++ b/rpkid/rpki/sql.py
@@ -62,12 +62,20 @@ class sql_persistant(object):
@classmethod
def sql_fetch(cls, gctx, id):
- """Fetch one object from SQL, based on its primary key. Since in
- this one case we know that the primary index is also the cache
- key, we check for a cache hit directly in the hope of bypassing the
- SQL lookup entirely.
+ """Fetch one object from SQL, based on its primary key.
+
+ Since in this one case we know that the primary index is also the
+ cache key, we check for a cache hit directly in the hope of
+ bypassing the SQL lookup entirely.
+
+ This method is usually called via a one-line class-specific
+ wrapper. As a convenience, we also accept an id of None, and just
+ return None in this case.
"""
- assert isinstance(id, (int, long))
+
+ if id is None:
+ return None
+ assert isinstance(id, (int, long)), "id should be an integer, was %s" % repr(type(id))
key = (cls, id)
if key in gctx.sql_cache:
return gctx.sql_cache[key]