Skip to content

Commit

Permalink
fix aggregate without enum value
Browse files Browse the repository at this point in the history
  • Loading branch information
mstingl committed Sep 29, 2024
1 parent 2137113 commit 297bb52
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
25 changes: 12 additions & 13 deletions djfapi/utils/fastapi_django.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
from decimal import Decimal
from enum import Enum
from functools import wraps
from typing import List, Optional, Union
from enum import Enum
from pydantic import BaseModel, Extra
from pydantic.error_wrappers import ErrorWrapper
from django.db.models import Q, QuerySet, Manager, aggregates
from django.db.utils import ProgrammingError

from django.core import signals
from django.db.models import Manager, Q, QuerySet, aggregates
from django.db.utils import ProgrammingError
from fastapi.exceptions import RequestValidationError
from pydantic import BaseModel, Extra
from pydantic.error_wrappers import ErrorWrapper

from .fastapi import Pagination

try:
Expand Down Expand Up @@ -49,16 +51,13 @@ def aggregation(
def aggregate():
query = objects.filter(q_filters)
fields = []
if distinct and field.value == '*':
raise RequestValidationError(
[ErrorWrapper(ValueError(), ('query', 'distinct'))]
)
value = field.value if isinstance(field, Enum) else field

if distinct and value == '*':
raise RequestValidationError([ErrorWrapper(ValueError(), ('query', 'distinct'))])

annotations = {
'value': getattr(
aggregates,
aggregation_function.value.title()
)(field.value, distinct=distinct),
'value': getattr(aggregates, aggregation_function.value.title())(value, distinct=distinct),
}

try:
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = djfapi
version = 0.0.72b24
version = 0.0.72b25
author = Manuel Stingl
author_email = [email protected]
description = Utilities for use with FastAPI and django
Expand Down

0 comments on commit 297bb52

Please sign in to comment.