From 3e0db059ec9555edc18ae6233ec7d646ddbebd4e Mon Sep 17 00:00:00 2001 From: Chad Birch Date: Fri, 8 May 2015 14:27:50 -0600 Subject: [PATCH] AutoMod: error if invalid search check for type If all of the fields in a search check are invalid for a type, we should throw an error instead of just quietly disregarding that search check. The previous behavior caused a rule with, for example, separate searches for both "domain" and "body" to apply to comments, even though the presence of a domain check should have caused it to be restricted to only submissions. --- r2/r2/lib/automoderator.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/r2/r2/lib/automoderator.py b/r2/r2/lib/automoderator.py index 7dd38502b..53eccf71f 100644 --- a/r2/r2/lib/automoderator.py +++ b/r2/r2/lib/automoderator.py @@ -620,6 +620,12 @@ class RuleTarget(object): valid_fields = self._match_fields_by_type[self.target_type] fields = {field for field in fields if field in valid_fields} + if not fields: + raise AutoModeratorRuleTypeError( + "Can't search `%s` on this type" % key, + self.parent.yaml, + ) + modifiers = matches.group(2) if modifiers: modifiers = [mod.strip() for mod in modifiers.split(",")]