aboutsummaryrefslogtreecommitdiffstats
path: root/pydis_site
diff options
context:
space:
mode:
authorGravatar MarkKoz <[email protected]>2019-12-18 19:51:26 -0800
committerGravatar MarkKoz <[email protected]>2019-12-18 19:51:26 -0800
commit4b25725167d1038874fc4b3e3eefb90b711d8913 (patch)
tree64ba88be1ae1810182d8483c87bda880e118341f /pydis_site
parentMerge pull request #300 from python-discord/#222-offensive-msg-autodeletion (diff)
Infractions: fix UniqueTogetherValidator incorrectly failing
The active infractions queryset only gets filtered by the fields specified. This meant that if the same user and type had another infraction instance which was active, the validator would fail. The validator assumes failure if it sees any items still in the queryset after filtering. By including the active field in the validator, the queryset will be filtered by the active field too. In the case described above, the queryset would end up empty because a no infractions which are active will ever match an active=False filter.
Diffstat (limited to 'pydis_site')
-rw-r--r--pydis_site/apps/api/serializers.py2
1 files changed, 1 insertions, 1 deletions
diff --git a/pydis_site/apps/api/serializers.py b/pydis_site/apps/api/serializers.py
index 52a82eac..e538a012 100644
--- a/pydis_site/apps/api/serializers.py
+++ b/pydis_site/apps/api/serializers.py
@@ -109,7 +109,7 @@ class InfractionSerializer(ModelSerializer):
validators = [
UniqueTogetherValidator(
queryset=Infraction.objects.filter(active=True),
- fields=['user', 'type'],
+ fields=['user', 'type', 'active'],
message='This user already has an active infraction of this type.',
)
]