Skip to content

Commit

Permalink
fix (#1856): call factory once in regular case (#1898)
Browse files Browse the repository at this point in the history
* fix (#1874): call factory once in regular case

* chore: bump version

* lint: fix mypy

* chore: fix pydantic 2.10 compatibility

---------

Co-authored-by: Kumaran Rajendhiran <[email protected]>
  • Loading branch information
Lancetnik and kumaranvpl authored Nov 7, 2024
1 parent fc61e91 commit 9c25b7b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
2 changes: 1 addition & 1 deletion faststream/__about__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Simple and fast framework to create message brokers based microservices."""

__version__ = "0.5.28"
__version__ = "0.5.29"

SERVICE_NAME = f"faststream-{__version__}"
11 changes: 8 additions & 3 deletions faststream/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,14 @@ def json_dumps(*a: Any, **kw: Any) -> bytes:
with_info_plain_validator_function as with_info_plain_validator_function,
)
else:
from pydantic._internal._annotated_handlers import ( # type: ignore[no-redef]
GetJsonSchemaHandler as GetJsonSchemaHandler,
)
if PYDANTIC_VERSION >= "2.10":
from pydantic.annotated_handlers import (
GetJsonSchemaHandler as GetJsonSchemaHandler,
)
else:
from pydantic._internal._annotated_handlers import ( # type: ignore[no-redef]
GetJsonSchemaHandler as GetJsonSchemaHandler,
)
from pydantic_core.core_schema import (
general_plain_validator_function as with_info_plain_validator_function,
)
Expand Down
21 changes: 19 additions & 2 deletions faststream/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,11 @@ def run(
_run(*args)

else:
_run(*args)
_run_imported_app(
app_obj,
extra_options=extra,
log_level=casted_log_level,
)


def _run(
Expand All @@ -168,11 +172,24 @@ def _run(
extra_options: Dict[str, "SettingField"],
is_factory: bool,
log_level: int = logging.NOTSET,
app_level: int = logging.INFO,
app_level: int = logging.INFO, # option for reloader only
) -> None:
"""Runs the specified application."""
_, app_obj = import_from_string(app, is_factory=is_factory)
_run_imported_app(
app_obj,
extra_options=extra_options,
log_level=log_level,
app_level=app_level,
)


def _run_imported_app(
app_obj: "Application",
extra_options: Dict[str, "SettingField"],
log_level: int = logging.NOTSET,
app_level: int = logging.INFO, # option for reloader only
) -> None:
if not isinstance(app_obj, Application):
raise typer.BadParameter(
f'Imported object "{app_obj}" must be "Application" type.',
Expand Down
4 changes: 2 additions & 2 deletions faststream/cli/utils/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import TYPE_CHECKING, DefaultDict, Optional, Union

if TYPE_CHECKING:
from faststream.app import FastStream
from faststream._internal.application import Application
from faststream.types import LoggerProto


Expand Down Expand Up @@ -64,7 +64,7 @@ def get_log_level(level: Union[LogLevels, str, int]) -> int:
return LOG_LEVELS[level.lower()]


def set_log_level(level: int, app: "FastStream") -> None:
def set_log_level(level: int, app: "Application") -> None:
"""Sets the log level for an application."""
if app.logger and getattr(app.logger, "setLevel", None):
app.logger.setLevel(level) # type: ignore[attr-defined]
Expand Down

0 comments on commit 9c25b7b

Please sign in to comment.