Skip to content

Commit 674389b

Browse files
committed
fixed issues with resolving route function parameters and request parameters
1 parent 84d31bd commit 674389b

File tree

7 files changed

+25
-20
lines changed

7 files changed

+25
-20
lines changed

ninja_extra/conf/decorator.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from pydantic.json_schema import JsonSchemaValue
66
from pydantic_core.core_schema import CoreSchema, with_info_plain_validator_function
77

8+
from ninja_extra.lazy import LazyStrImport
89
from ninja_extra.shortcuts import fail_silently
910

1011

@@ -29,6 +30,8 @@ def validate(value: t.Any, *args: t.Any) -> t.Any:
2930
try_import_value = fail_silently(import_string, value)
3031
if try_import_value is not None:
3132
value = try_import_value
33+
else:
34+
value = LazyStrImport(value)
3235

3336
if (self.validator and not self.validator(source, value)) or (
3437
not self.validator and not isinstance(value, source)

ninja_extra/conf/package_settings.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
error_message=lambda source,
1919
value: f"Expected type of {source.__name__}, received: {type(value)}",
2020
)
21+
2122
PaginationClassHandlerType = Annotated[PaginationBase, _GenericModelValidator]
2223
ThrottlingClassHandlerType = Annotated[BaseThrottle, _GenericModelValidator]
2324
SearchingClassHandlerType = Annotated[SearchingBase, _GenericModelValidator]
@@ -34,7 +35,7 @@
3435

3536
class UserDefinedSettingsMapper:
3637
def __init__(self, data: dict) -> None:
37-
self.__dict__ = data
38+
self.__dict__ = dict(NinjaEXTRA_SETTINGS_DEFAULTS, **data)
3839

3940

4041
NinjaEXTRA_SETTINGS_DEFAULTS = {

ninja_extra/context.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def __init__(
5252
self.response = response
5353
self.args: t.List[t.Any] = args or []
5454
self.kwargs: DictStrAny = kwargs or {}
55+
self.kwargs.update({"view_func_kwargs": {}})
5556
self.permission_classes: PermissionType = permission_classes or []
5657
self._api = api
5758
self._view_signature = view_signature
@@ -102,7 +103,7 @@ def compute_route_parameters(
102103
if self._view_signature.response_arg:
103104
values[self._view_signature.response_arg] = self.response
104105

105-
self.kwargs.update(values)
106+
self.kwargs.update({"view_func_kwargs": values}, **values)
106107
self._has_computed_route_parameters = True
107108

108109

ninja_extra/controllers/base.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -400,9 +400,9 @@ def __call__(self, cls: ControllerClassType) -> ControllerClassType:
400400
else:
401401
cls._api_controller = self
402402

403-
assert isinstance(
404-
cls.throttling_classes, (list, tuple)
405-
), f"Controller[{cls.__name__}].throttling_class must be a list or tuple"
403+
assert isinstance(cls.throttling_classes, (list, tuple)), (
404+
f"Controller[{cls.__name__}].throttling_class must be a list or tuple"
405+
)
406406

407407
throttling_objects: Union[BaseThrottle, List[BaseThrottle], NOT_SET_TYPE] = (
408408
NOT_SET
@@ -424,9 +424,9 @@ def __call__(self, cls: ControllerClassType) -> ControllerClassType:
424424

425425
if issubclass(cls, ModelControllerBase):
426426
if cls.model_config:
427-
assert (
428-
cls.service_type is not None
429-
), "service_type is required for ModelControllerBase"
427+
assert cls.service_type is not None, (
428+
"service_type is required for ModelControllerBase"
429+
)
430430
# if model_config is not provided, treat controller class as normal
431431
builder = ModelControllerBuilder(cls, self)
432432
builder.register_model_routes()

ninja_extra/controllers/model/endpoints.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -707,9 +707,9 @@ async def patch_item(
707707
)
708708
instance = await _check_if_coroutine(instance)
709709

710-
assert (
711-
instance
712-
), "`service.patch_async()` or `custom_handler` must return a value"
710+
assert instance, (
711+
"`service.patch_async()` or `custom_handler` must return a value"
712+
)
713713
return instance
714714

715715
patch_item.__name__ = cls._change_name("patch_item")
@@ -748,9 +748,9 @@ async def update_item(
748748
)
749749
instance = await _check_if_coroutine(instance)
750750

751-
assert (
752-
instance
753-
), "`service.update_async` or `custom_handler` must return a value"
751+
assert instance, (
752+
"`service.update_async` or `custom_handler` must return a value"
753+
)
754754
return instance
755755

756756
update_item.__name__ = cls._change_name("update_item")
@@ -775,9 +775,9 @@ async def create_item(
775775
)
776776
instance = await _check_if_coroutine(instance)
777777

778-
assert (
779-
instance
780-
), "`service.create_async` or `custom_handler` must return a value"
778+
assert instance, (
779+
"`service.create_async` or `custom_handler` must return a value"
780+
)
781781
return instance
782782

783783
create_item.__name__ = cls._change_name("create_item")

ninja_extra/controllers/response.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from ninja import Schema
1010

11-
from .. import status
11+
from ninja_extra import status
1212

1313

1414
class ControllerResponse:

ninja_extra/operation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def run(self, request: HttpRequest, **kw: Any) -> HttpResponseBase:
211211
if not ctx.has_computed_route_parameters:
212212
ctx.compute_route_parameters()
213213

214-
result = self.view_func(request, **ctx.kwargs)
214+
result = self.view_func(request, **ctx.kwargs["view_func_kwargs"])
215215
assert ctx.response is not None
216216
_processed_results = self._result_to_response(
217217
request, result, ctx.response
@@ -345,7 +345,7 @@ async def run(self, request: HttpRequest, **kw: Any) -> HttpResponseBase: # typ
345345
if not ctx.has_computed_route_parameters:
346346
ctx.compute_route_parameters()
347347

348-
result = await self.view_func(request, **ctx.kwargs)
348+
result = await self.view_func(request, **ctx.kwargs["view_func_kwargs"])
349349
assert ctx.response is not None
350350
_processed_results = await self._result_to_response(
351351
request, result, ctx.response

0 commit comments

Comments
 (0)