Skip to content

Commit 8f5a1dd

Browse files
committed
fixed keyerror when resolving api versioning
1 parent 34362e4 commit 8f5a1dd

File tree

4 files changed

+61
-3
lines changed

4 files changed

+61
-3
lines changed

ellar/core/conf/app_settings_models.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import secrets
12
import typing as t
23

34
from ellar.common import EllarInterceptor, GuardCanActivate
@@ -253,3 +254,60 @@ def pre_cache_validate(cls, value: t.Dict) -> t.Any:
253254

254255

255256
ConfigSchema.model_rebuild()
257+
258+
259+
def default_config_settings():
260+
from ellar.common import JSONResponse
261+
from ellar.core.versioning import DefaultAPIVersioning
262+
from ellar.pydantic import ENCODERS_BY_TYPE as encoders_by_type
263+
264+
return {
265+
"DEBUG": False,
266+
"DEFAULT_JSON_CLASS": JSONResponse,
267+
"SECRET_KEY": secrets.token_hex(16),
268+
# injector auto_bind = True allows you to resolve types that are not registered on the container
269+
# For more info, read: https://injector.readthedocs.io/en/latest/index.html
270+
"INJECTOR_AUTO_BIND": False,
271+
# jinja Environment options
272+
# https://jinja.palletsprojects.com/en/3.0.x/api/#high-level-api
273+
"JINJA_TEMPLATES_OPTIONS": {},
274+
# Injects context to jinja templating context values
275+
"TEMPLATES_CONTEXT_PROCESSORS": [
276+
"ellar.core.templating.context_processors:request_context",
277+
"ellar.core.templating.context_processors:user",
278+
"ellar.core.templating.context_processors:request_state",
279+
],
280+
# Application route versioning scheme
281+
"VERSIONING_SCHEME": DefaultAPIVersioning(),
282+
# Enable or Disable Application Router route searching by appending backslash
283+
"REDIRECT_SLASHES": False,
284+
# Define references to static folders in python packages.
285+
# eg STATIC_FOLDER_PACKAGES = [('boostrap4', 'statics')]
286+
"STATIC_FOLDER_PACKAGES": [],
287+
# Define references to static folders defined within the project
288+
"STATIC_DIRECTORIES": [],
289+
# static route path
290+
"STATIC_MOUNT_PATH": "/static",
291+
"CORS_ALLOW_ORIGINS": ["*"],
292+
"CORS_ALLOW_METHODS": ["*"],
293+
"CORS_ALLOW_HEADERS": ["*"],
294+
"ALLOWED_HOSTS": ["*"],
295+
# Application middlewares
296+
"MIDDLEWARE": [
297+
"ellar.core.middleware.trusted_host:trusted_host_middleware",
298+
"ellar.core.middleware.cors:cors_middleware",
299+
"ellar.core.middleware.errors:server_error_middleware",
300+
"ellar.core.middleware.versioning:versioning_middleware",
301+
"ellar.auth.middleware.session:session_middleware",
302+
"ellar.auth.middleware.auth:identity_middleware",
303+
"ellar.core.middleware.exceptions:exception_middleware",
304+
],
305+
# A dictionary mapping either integer status codes,
306+
# or exception class types onto callables which handle the exceptions.
307+
# Exception handler callables should be of the form
308+
# `handler(context:IExecutionContext, exc: Exception) -> response`
309+
# and may be either standard functions, or async functions.
310+
"EXCEPTION_HANDLERS": ["ellar.core.exceptions:error_404_handler"],
311+
# Object Serializer custom encoders
312+
"SERIALIZER_CUSTOM_ENCODER": encoders_by_type,
313+
}

ellar/core/conf/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Config(ConfigDefaultTypesMixin):
2222

2323
def __init__(
2424
self,
25-
config_module: t.Optional[str] = None,
25+
config_module: t.Optional[t.Union[str, dict]] = None,
2626
config_prefix: t.Optional[str] = None,
2727
**mapping: t.Any,
2828
):

ellar/core/routing/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def matches(self, scope: TScope) -> t.Tuple[Match, TScope]:
120120
if match[0] is Match.FULL:
121121
version_scheme_resolver: "BaseAPIVersioningResolver" = t.cast(
122122
"BaseAPIVersioningResolver",
123-
scope[constants.SCOPE_API_VERSIONING_RESOLVER],
123+
scope.get(constants.SCOPE_API_VERSIONING_RESOLVER),
124124
)
125125
if not version_scheme_resolver.can_activate(
126126
route_versions=self.allowed_version

ellar/core/routing/mount.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def router_default_decorator(func: ASGIApp) -> ASGIApp:
116116
@functools.wraps(func)
117117
async def _wrap(scope: TScope, receive: TReceive, send: TSend) -> None:
118118
version_scheme_resolver: "BaseAPIVersioningResolver" = t.cast(
119-
"BaseAPIVersioningResolver", scope[SCOPE_API_VERSIONING_RESOLVER]
119+
"BaseAPIVersioningResolver", scope.get(SCOPE_API_VERSIONING_RESOLVER)
120120
)
121121
if version_scheme_resolver and version_scheme_resolver.matched_any_route:
122122
version_scheme_resolver.raise_exception()

0 commit comments

Comments
 (0)