diff --git a/r2/r2/controllers/api.py b/r2/r2/controllers/api.py index a204684a7..84a0db721 100644 --- a/r2/r2/controllers/api.py +++ b/r2/r2/controllers/api.py @@ -490,6 +490,7 @@ class ApiController(RedditController): VModhash(), thing = VByNameIfAuthor('id')) def POST_del(self, thing): + if not thing: return '''for deleting all sorts of things''' thing._deleted = True thing._commit() @@ -986,6 +987,7 @@ class ApiController(RedditController): VSrCanBan('id'), thing = VByName('id')) def POST_ban(self, thing): + if not thing: return thing.moderator_banned = not c.user_is_admin thing.banner = c.user.name thing._commit() @@ -997,12 +999,14 @@ class ApiController(RedditController): thing = VByName('id')) def POST_unban(self, thing): # NB: change table updated by reporting + if not thing: return unreport(thing, correct=False) @noresponse(VModhash(), VSrCanBan('id'), thing = VByName('id')) def POST_ignore(self, thing): + if not thing: return # NB: change table updated by reporting unreport(thing, correct=False) @@ -1010,6 +1014,7 @@ class ApiController(RedditController): VModhash(), thing = VByName('id')) def POST_save(self, thing): + if not thing: return r = thing._save(c.user) if g.write_query_queue: queries.new_savehide(r) @@ -1018,6 +1023,7 @@ class ApiController(RedditController): VModhash(), thing = VByName('id')) def POST_unsave(self, thing): + if not thing: return r = thing._unsave(c.user) if g.write_query_queue and r: queries.new_savehide(r) @@ -1026,6 +1032,7 @@ class ApiController(RedditController): VModhash(), thing = VByName('id')) def POST_hide(self, thing): + if not thing: return r = thing._hide(c.user) if g.write_query_queue: queries.new_savehide(r) @@ -1034,6 +1041,7 @@ class ApiController(RedditController): VModhash(), thing = VByName('id')) def POST_unhide(self, thing): + if not thing: return r = thing._unhide(c.user) if g.write_query_queue and r: queries.new_savehide(r) @@ -1226,6 +1234,7 @@ class ApiController(RedditController): @noresponse(VSponsor(), thing = VByName('id')) def POST_unpromote(self, thing): + if not thing: return unpromote(thing) @validatedForm(VSponsor(), diff --git a/r2/r2/lib/app_globals.py b/r2/r2/lib/app_globals.py index ec703bbf7..76b032cd6 100644 --- a/r2/r2/lib/app_globals.py +++ b/r2/r2/lib/app_globals.py @@ -184,14 +184,14 @@ class Globals(object): return (x.strip() for x in v.split(delim)) def load_db_params(self, gc): - databases = self.to_iter(gc['databases']) - if not databases: + self.databases = tuple(self.to_iter(gc['databases'])) + if not self.databases: return dbm = db_manager.db_manager() db_params = ('name', 'db_host', 'db_user', 'db_pass', 'pool_size', 'max_overflow') - for db_name in databases: + for db_name in self.databases: conf_params = self.to_iter(gc[db_name + '_db']) params = dict(zip(db_params, conf_params)) dbm.engines[db_name] = db_manager.get_engine(**params) diff --git a/r2/supervise_watcher.py b/r2/supervise_watcher.py index 7aa7e8400..450ef3788 100644 --- a/r2/supervise_watcher.py +++ b/r2/supervise_watcher.py @@ -34,10 +34,8 @@ def is_db_machine(host): Given a host name, checks the list of known DB machines to determine if the host is one of them. """ - ips = set(v for k,v in g._current_obj().__dict__.iteritems() - if k.endswith("db_host")) - - for ip in ips: + for db in g.databases: + ip = list(g.to_iter(getattr(g, db + "_db")))[1] name = socket.gethostbyaddr(ip)[0] if (name == host or ("." in host and name.endswith("." + host)) or name.startswith(host + ".")):