From e9f567ffc9436530a4c18393f0da75404334f3e0 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Sat, 22 Sep 2018 23:10:18 -0700 Subject: [PATCH] Don't allow Groupable to add itself as a child. omg what an oversight --- etiquette/exceptions.py | 3 +++ etiquette/objects.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/etiquette/exceptions.py b/etiquette/exceptions.py index b070a69..fac32af 100644 --- a/etiquette/exceptions.py +++ b/etiquette/exceptions.py @@ -109,6 +109,9 @@ class UserExists(Exists): # TAG ERRORS +class CantGroupSelf(EtiquetteException): + error_message = 'Cannot group {} into itself.' + class CantSynonymSelf(EtiquetteException): error_message = 'Cannot apply synonym to self.' diff --git a/etiquette/objects.py b/etiquette/objects.py index 8b3ae08..5c00b92 100644 --- a/etiquette/objects.py +++ b/etiquette/objects.py @@ -87,6 +87,9 @@ class GroupableMixin: def add_child(self, member, *, commit=True): self.assert_same_type(member) + if member == self: + raise exceptions.CantGroupSelf(self) + if self.has_child(member): return