Skip to content

Commit 5d91e5e

Browse files
committed
fix alert import, compat for django 3 in queryset
1 parent 5afd370 commit 5d91e5e

2 files changed

Lines changed: 17 additions & 8 deletions

File tree

utilmeta/core/orm/backends/django/queryset.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,8 @@ async def afirst(self):
670670
if self.ordered:
671671
queryset = self
672672
else:
673-
self._check_ordering_first_last_queryset_aggregation(method="first")
673+
if django.VERSION >= (4, 0):
674+
self._check_ordering_first_last_queryset_aggregation(method="first")
674675
queryset = self.order_by("pk")
675676
async for obj in queryset[:1]:
676677
return obj
@@ -681,7 +682,8 @@ async def alast(self):
681682
if self.ordered:
682683
queryset = self.reverse()
683684
else:
684-
self._check_ordering_first_last_queryset_aggregation(method="last")
685+
if django.VERSION >= (4, 0):
686+
self._check_ordering_first_last_queryset_aggregation(method="last")
685687
queryset = self.order_by("-pk")
686688
async for obj in queryset[:1]:
687689
return obj
@@ -932,15 +934,19 @@ async def abulk_create(
932934
Internal django implementation of bulk_create is too complicate to split into async code
933935
and since it's async, we can do a async joined task to create all objects
934936
"""
935-
if not self.support_pure_async:
937+
if not self.support_pure_async or django.VERSION < (4, 0):
938+
params = dict(
939+
update_conflicts=update_conflicts,
940+
update_fields=update_fields,
941+
unique_fields=unique_fields,
942+
) if django.VERSION >= (4, 0) else {}
936943
return await sync_to_async(self.bulk_create)(
937944
objs,
938945
batch_size=batch_size,
939946
ignore_conflicts=ignore_conflicts,
940-
update_conflicts=update_conflicts,
941-
update_fields=update_fields,
942-
unique_fields=unique_fields,
947+
**params
943948
)
949+
944950
if not objs:
945951
return objs
946952
has_parent = None
@@ -1184,7 +1190,11 @@ async def aget(self, *args, **kwargs):
11841190
if not self.support_pure_async:
11851191
return await sync_to_async(self.get)(*args, **kwargs)
11861192
if self.query.combinator and (args or kwargs):
1187-
raise exceptions.NotSupportedError(
1193+
if django.VERSION < (4, 0):
1194+
cls = exceptions.FieldError
1195+
else:
1196+
cls = exceptions.NotSupportedError
1197+
raise cls(
11881198
"Calling QuerySet.get(...) with filters after %s() is not "
11891199
"supported." % self.query.combinator
11901200
)

utilmeta/ops/alert/config.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import pytz
21
from utype.types import *
32
from utilmeta.conf import Config
43
from django.db import models

0 commit comments

Comments
 (0)