Skip to content

Commit

Permalink
Use same order with nulls between SQLite and PostgreSQL
Browse files Browse the repository at this point in the history
  • Loading branch information
vrigal committed Oct 18, 2024
1 parent 6094d4f commit 2053dd0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
9 changes: 8 additions & 1 deletion backend/code_review_backend/issues/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from datetime import date, datetime, timedelta

from django.conf import settings
from django.db.models import Count, Prefetch, Q
from django.db.models import BooleanField, Count, ExpressionWrapper, Prefetch, Q
from django.db.models.functions import TruncDate
from django.shortcuts import get_object_or_404
from django.urls import path
Expand Down Expand Up @@ -309,6 +309,11 @@ def get_queryset(self):
)
# We want to count distinct issues because they can be referenced on multiple diffs
.annotate(total=Count("id", distinct=True))
.annotate(
has_check=ExpressionWrapper(
Q(analyzer_check__isnull=True), output_field=BooleanField()
)
)
.annotate(
publishable=Count(
"id", filter=Q(issue_links__in_patch=True) | Q(level=LEVEL_ERROR)
Expand Down Expand Up @@ -338,6 +343,8 @@ def get_queryset(self):
"-total",
"issue_links__revision__head_repository__slug",
"analyzer",
# Use same order than PostgreSQL with SQLite
"has_check",
"analyzer_check",
).values(
"issue_links__revision__head_repository__slug",
Expand Down
19 changes: 10 additions & 9 deletions backend/code_review_backend/issues/tests/test_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ def test_stats(self):
"""
response = self.client.get("/v1/check/stats/")
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.maxDiff = None
self.assertDictEqual(
response.json(),
{
Expand All @@ -126,14 +127,14 @@ def test_stats(self):
},
{
"analyzer": "analyzer-Y",
"check": None,
"check": "check-10",
"publishable": 0,
"repository": "myrepo-try",
"total": 34,
},
{
"analyzer": "analyzer-Y",
"check": "check-10",
"check": None,
"publishable": 0,
"repository": "myrepo-try",
"total": 34,
Expand All @@ -147,21 +148,21 @@ def test_stats(self):
},
{
"analyzer": "analyzer-X",
"check": None,
"check": "check-10",
"publishable": 0,
"repository": "myrepo-try",
"total": 33,
},
{
"analyzer": "analyzer-X",
"check": "check-10",
"check": "check-42",
"publishable": 0,
"repository": "myrepo-try",
"total": 33,
},
{
"analyzer": "analyzer-X",
"check": "check-42",
"check": None,
"publishable": 0,
"repository": "myrepo-try",
"total": 33,
Expand Down Expand Up @@ -189,28 +190,28 @@ def test_stats(self):
},
{
"analyzer": "analyzer-Z",
"check": None,
"check": "check-1",
"publishable": 0,
"repository": "myrepo-try",
"total": 33,
},
{
"analyzer": "analyzer-Z",
"check": "check-1",
"check": "check-10",
"publishable": 0,
"repository": "myrepo-try",
"total": 33,
},
{
"analyzer": "analyzer-Z",
"check": "check-10",
"check": "check-1000",
"publishable": 0,
"repository": "myrepo-try",
"total": 33,
},
{
"analyzer": "analyzer-Z",
"check": "check-1000",
"check": None,
"publishable": 0,
"repository": "myrepo-try",
"total": 33,
Expand Down

0 comments on commit 2053dd0

Please sign in to comment.