Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: incorrect parsing of path parameters with nested routers #1765

Closed
ulbwa opened this issue Sep 5, 2024 · 0 comments · Fixed by #1789
Closed

Bug: incorrect parsing of path parameters with nested routers #1765

ulbwa opened this issue Sep 5, 2024 · 0 comments · Fixed by #1789
Labels
bug Something isn't working good first issue Good for newcomers NATS Issues related to `faststream.nats` module and NATS broker features

Comments

@ulbwa
Copy link
Contributor

ulbwa commented Sep 5, 2024

Describe the bug
When using nested routers with path parameters, the values are parsed incorrectly. Specifically, when passing a valid enum value in the subject, only the last character of the path parameter is taken.

How to reproduce

from enum import StrEnum
from typing import Annotated, Any

from faststream import FastStream, Path
from faststream.nats import NatsBroker, NatsRouter


class MyEnum(StrEnum):
    FIRST = "first"
    SECOND = "second"
    THIRD = "third"


broker = NatsBroker()
root_router = NatsRouter(prefix="root_router.")
nested_router = NatsRouter()


@nested_router.subscriber("{my_enum}.nested_router")
async def do_nothing(message: Any, my_enum: Annotated[MyEnum, Path()]): ...


root_router.include_router(nested_router)
broker.include_router(nested_router)
app = FastStream(broker)


@app.after_startup
async def run():
    await broker.publish("", f"root_router.{MyEnum.THIRD}.nested_router")

Expected behavior
The my_enum path parameter should be correctly parsed, matching the full enum value (e.g., “third”).

Observed behavior

pydantic_core._pydantic_core.ValidationError: 1 validation error for do_nothing
my_enum
  Input should be 'first', 'second' or 'third' [type=enum, input_value='d', input_type=str]
    For further information visit https://errors.pydantic.dev/2.8/v/enum
@ulbwa ulbwa added the bug Something isn't working label Sep 5, 2024
@Lancetnik Lancetnik added good first issue Good for newcomers NATS Issues related to `faststream.nats` module and NATS broker features labels Sep 5, 2024
@Lancetnik Lancetnik mentioned this issue Sep 10, 2024
Flosckow pushed a commit to Flosckow/faststream that referenced this issue Sep 13, 2024
github-merge-queue bot pushed a commit that referenced this issue Sep 13, 2024
* Fix: this commit resolve #1765

* tests: refactor test

---------

Co-authored-by: Daniil Dumchenko <[email protected]>
Co-authored-by: Nikita Pastukhov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers NATS Issues related to `faststream.nats` module and NATS broker features
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants