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

Wrong error message in broker handler #49

Closed
asarkhipov opened this issue Jun 3, 2023 · 3 comments
Closed

Wrong error message in broker handler #49

asarkhipov opened this issue Jun 3, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@asarkhipov
Copy link

Describe the bug
When I made a mistake specifying the argument type, I received an error.

To Reproduce
Add source code

from propan import KafkaBroker, PropanApp

broker = KafkaBroker()
app = PropanApp(broker)


class A:
    ...


@broker.handle("test-topic", auto_offset_reset="earliest")
async def hello(msg: str, a: A):
    print(msg)

Result:

2023-06-03 14:49:12,214 ERROR    - Invalid args for response field! Hint: check that <class 'mode.A'> is a valid pydantic field type
2023-06-03 14:49:12,214 ERROR    - Please, input module like [python_file:propan_app_name]

And steps to reproduce the behavior:

  1. Run the code

Expected behavior
More informative output, that tell something like "In the main.py file, on line 12, the argument 'a' has type A. It was expected to have type pydantic field and a default value of Depends or Context."

Environment
Running Propan 0.1.2.7 with CPython 3.10.10 on Linux

@asarkhipov asarkhipov added the bug Something isn't working label Jun 3, 2023
@Lancetnik
Copy link
Owner

Lancetnik commented Jun 3, 2023

It's a not Propan error. The framework builds pydantic.BaseModel by your function arguments.

Because the following code is not correct, your function annotation is not correct too.

from pydantic import BaseModel

class A:
   ...

class Model(BaseModel):
    a: A

You should use python primitives or pydantic.BaseModel to annotate your handler arguments.

P.S: the same behavior you can see in FastAPI

@Lancetnik Lancetnik added the invalid This doesn't seem right label Jun 3, 2023
@asarkhipov
Copy link
Author

I know that my function argument is incorrect, but issue about error messages:
Invalid args for response field! - A is not response field, it is handler argument. If code base is big, this is hard to find there it is being used
Please, input module like [python_file:propan_app_name] - I run it correct, why i get this?

@Lancetnik
Copy link
Owner

Well, it makes sense

@Lancetnik Lancetnik removed the invalid This doesn't seem right label Jun 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants