From 3e40a58d423fa015fa4278e029ecbf0c24610cf8 Mon Sep 17 00:00:00 2001 From: Keith Mitchell Date: Tue, 27 Mar 2012 13:17:48 -0700 Subject: [PATCH] Get rid of check_essentials hack --- r2/r2/lib/db/thing.py | 20 ++++++++------------ r2/r2/lib/utils/utils.py | 2 +- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/r2/r2/lib/db/thing.py b/r2/r2/lib/db/thing.py index f4c7a2cd4..3d69bee26 100644 --- a/r2/r2/lib/db/thing.py +++ b/r2/r2/lib/db/thing.py @@ -270,7 +270,7 @@ class DataThing(object): self._cache_myself() @classmethod - def _load_multi(cls, need, check_essentials=True): + def _load_multi(cls, need): need = tup(need) need_ids = [n._id for n in need] datas = cls._get_data(cls._type_id, need_ids) @@ -285,13 +285,9 @@ class DataThing(object): i._t.update(datas.get(i._id, i._t)) i._loaded = True - for essential in essentials: - if essential not in i._t: - if check_essentials: - raise AttributeError("Refusing to cache %s; it's missing %s" - % (i._fullname, essential)) - else: - print "Warning: %s is missing %s" % (i._fullname, essential) + for attr in essentials: + if attr not in i._t: + print "Warning: %s is missing %s" % (i._fullname, attr) i._asked_for_data = True to_save[i._id] = i @@ -300,8 +296,8 @@ class DataThing(object): #write the data to the cache cache.set_multi(to_save, prefix=prefix) - def _load(self, check_essentials=True): - self._load_multi(self, check_essentials) + def _load(self): + self._load_multi(self) def _safe_load(self): if not self._loaded: @@ -352,7 +348,7 @@ class DataThing(object): #TODO error when something isn't found? @classmethod def _byID(cls, ids, data=False, return_dict=True, extra_props=None, - stale=False, check_essentials=True): + stale=False): ids, single = tup(ids, True) prefix = thing_prefix(cls.__name__) @@ -387,7 +383,7 @@ class DataThing(object): if not v._loaded: need.append(v) if need: - cls._load_multi(need, check_essentials) + cls._load_multi(need) ### The following is really handy for debugging who's forgetting data=True: # else: # for v in bases.itervalues(): diff --git a/r2/r2/lib/utils/utils.py b/r2/r2/lib/utils/utils.py index 7a4d7cb3b..4730610d0 100644 --- a/r2/r2/lib/utils/utils.py +++ b/r2/r2/lib/utils/utils.py @@ -824,7 +824,7 @@ def fix_if_broken(thing, delete = True, fudge_links = False): if not tried_loading: tried_loading = True - thing._load(check_essentials=False) + thing._load() try: getattr(thing, attr)