From 528e017eb50756689b54af4d0009da30e8c00202 Mon Sep 17 00:00:00 2001 From: Manuel Stingl Date: Sun, 29 Sep 2024 13:21:56 +0200 Subject: [PATCH] fix error handling --- djfapi/routing/django.py | 27 ++++++++++++++------------- setup.cfg | 2 +- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/djfapi/routing/django.py b/djfapi/routing/django.py index 8a4d911..f3f2c5e 100644 --- a/djfapi/routing/django.py +++ b/djfapi/routing/django.py @@ -2,8 +2,7 @@ from datetime import date from enum import Enum from functools import cached_property, wraps -from typing import (Any, Dict, Generator, Iterable, List, Optional, Tuple, - Type, TypeVar, Union) +from typing import Any, Dict, Generator, Iterable, List, Optional, Tuple, Type, TypeVar, Union import forge from django.db import connections, models @@ -11,13 +10,17 @@ from djdantic.schemas import Access, Error from djdantic.schemas.access import AccessScope from djdantic.utils.dict import remove_none -from djdantic.utils.pydantic import (IdAddedModel, OptionalModel, - ReferencedModel, id_added_model, - include_reference, optional_model) +from djdantic.utils.pydantic import ( + IdAddedModel, + OptionalModel, + ReferencedModel, + id_added_model, + include_reference, + optional_model, +) from djdantic.utils.pydantic_django import TransferAction, transfer_to_orm from djdantic.utils.typing import get_field_type -from fastapi import (APIRouter, Body, Depends, Path, Query, Request, Response, - Security) +from fastapi import APIRouter, Body, Depends, Path, Query, Request, Response, Security from fastapi._compat import _normalize_errors from fastapi.dependencies.utils import analyze_param, request_params_to_args from fastapi.exceptions import RequestValidationError @@ -29,10 +32,8 @@ from ..exceptions import AccessError, ValidationError from ..schemas import errors as error_schemas from ..utils.fastapi import Pagination, depends_pagination -from ..utils.fastapi_django import (AggregateResponse, AggregationFunction, - aggregation, request_signalling) -from . import ( # noqa # import SecurityScopes for user friendly import - Method, RouterSchema, SecurityScopes) +from ..utils.fastapi_django import AggregateResponse, AggregationFunction, aggregation, request_signalling +from . import Method, RouterSchema, SecurityScopes # noqa # import SecurityScopes for user friendly import from .base import TBaseModel, TCreateModel, TUpdateModel from .registry import register_router @@ -720,7 +721,7 @@ def search_filter_fields( value=Query(**options), is_path_param=False, ) - fields[name] = getattr(param, 'field') or param[2] + fields[name] = getattr(param, 'field', None) or param[2] param_not = analyze_param( param_name=f'not__{name}', @@ -728,7 +729,7 @@ def search_filter_fields( value=Query(**{**options, 'alias': '!' + options.get('alias', name)}), is_path_param=False, ) - fields[f'not__{name}'] = getattr(param_not, 'field') or param_not[2] + fields[f'not__{name}'] = getattr(param_not, 'field', None) or param_not[2] return fields diff --git a/setup.cfg b/setup.cfg index 6bd31e1..1af5154 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = djfapi -version = 0.0.72b22 +version = 0.0.72b23 author = Manuel Stingl author_email = opensource@voltane.eu description = Utilities for use with FastAPI and django