From 1e4fc52531de04d278b25958568e53c12f144938 Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Sat, 1 Apr 2023 01:07:17 -0400 Subject: [PATCH] Re-add `ExpressionWrapper` to `CertificationVersionManager` annotations Not sure why I removed them, but things sure are broken without them --- paperwork/models.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/paperwork/models.py b/paperwork/models.py index 0c337cb..6a4cdf0 100644 --- a/paperwork/models.py +++ b/paperwork/models.py @@ -2,7 +2,7 @@ import re from semver import VersionInfo from django.db import models -from django.db.models import OuterRef, Q, Subquery +from django.db.models import OuterRef, Q, ExpressionWrapper, Subquery from django.core.validators import RegexValidator from membershipworks.models import Member, Flag as MembershipWorksFlag @@ -110,9 +110,15 @@ class CertificationVersionManager(models.Manager): qs = super().get_queryset() latest = qs.filter(definition__pk=OuterRef("definition__pk")).reverse() return qs.annotate( - is_latest=Q(pk=Subquery(latest.values("pk")[:1])), + is_latest=ExpressionWrapper( + Q(pk=Subquery(latest.values("pk")[:1])), + output_field=models.BooleanField(), + ), # TODO: should do a more correct comparison than just major version - is_current=Q(major=Subquery(latest.values("major")[:1])), + is_current=ExpressionWrapper( + Q(major=Subquery(latest.values("major")[:1])), + output_field=models.BooleanField(), + ), )