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.
This commit is contained in:
Chad Birch
2015-05-08 14:27:50 -06:00
parent 040cf0884d
commit 3e0db059ec

View File

@@ -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(",")]