Skip to content

Commit 9c25b7b

Browse files
fix (#1856): call factory once in regular case (#1898)
* 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 <kumaran@airt.ai>
1 parent fc61e91 commit 9c25b7b

File tree

4 files changed

+30
-8
lines changed

4 files changed

+30
-8
lines changed

faststream/__about__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""Simple and fast framework to create message brokers based microservices."""
22

3-
__version__ = "0.5.28"
3+
__version__ = "0.5.29"
44

55
SERVICE_NAME = f"faststream-{__version__}"

faststream/_compat.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,14 @@ def json_dumps(*a: Any, **kw: Any) -> bytes:
6666
with_info_plain_validator_function as with_info_plain_validator_function,
6767
)
6868
else:
69-
from pydantic._internal._annotated_handlers import ( # type: ignore[no-redef]
70-
GetJsonSchemaHandler as GetJsonSchemaHandler,
71-
)
69+
if PYDANTIC_VERSION >= "2.10":
70+
from pydantic.annotated_handlers import (
71+
GetJsonSchemaHandler as GetJsonSchemaHandler,
72+
)
73+
else:
74+
from pydantic._internal._annotated_handlers import ( # type: ignore[no-redef]
75+
GetJsonSchemaHandler as GetJsonSchemaHandler,
76+
)
7277
from pydantic_core.core_schema import (
7378
general_plain_validator_function as with_info_plain_validator_function,
7479
)

faststream/cli/main.py

+19-2
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,11 @@ def run(
159159
_run(*args)
160160

161161
else:
162-
_run(*args)
162+
_run_imported_app(
163+
app_obj,
164+
extra_options=extra,
165+
log_level=casted_log_level,
166+
)
163167

164168

165169
def _run(
@@ -168,11 +172,24 @@ def _run(
168172
extra_options: Dict[str, "SettingField"],
169173
is_factory: bool,
170174
log_level: int = logging.NOTSET,
171-
app_level: int = logging.INFO,
175+
app_level: int = logging.INFO, # option for reloader only
172176
) -> None:
173177
"""Runs the specified application."""
174178
_, app_obj = import_from_string(app, is_factory=is_factory)
179+
_run_imported_app(
180+
app_obj,
181+
extra_options=extra_options,
182+
log_level=log_level,
183+
app_level=app_level,
184+
)
185+
175186

187+
def _run_imported_app(
188+
app_obj: "Application",
189+
extra_options: Dict[str, "SettingField"],
190+
log_level: int = logging.NOTSET,
191+
app_level: int = logging.INFO, # option for reloader only
192+
) -> None:
176193
if not isinstance(app_obj, Application):
177194
raise typer.BadParameter(
178195
f'Imported object "{app_obj}" must be "Application" type.',

faststream/cli/utils/logs.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from typing import TYPE_CHECKING, DefaultDict, Optional, Union
55

66
if TYPE_CHECKING:
7-
from faststream.app import FastStream
7+
from faststream._internal.application import Application
88
from faststream.types import LoggerProto
99

1010

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

6666

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

0 commit comments

Comments
 (0)