Skip to content

Commit

Permalink
AutoMod: error if invalid search check for type
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Deimos committed May 12, 2015
1 parent 040cf08 commit 3e0db05
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions r2/r2/lib/automoderator.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,12 @@ def parse_match_fields_key(self, key):
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(",")]
Expand Down

0 comments on commit 3e0db05

Please sign in to comment.