-
-
Notifications
You must be signed in to change notification settings - Fork 455
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] Type checker does not recognize fields on ModelSchema Meta #1382
Comments
there are few concerns in your code
so no way to debug or find any reasons |
Hi @vitalik 👋 Sorry, you're absolutely right. 🙏 Here is the complete context that I forgot to add on my initial post. I'm using Django Ninja Extra, where it has the from ninja import ModelSchema, NinjaAPI
from ninja_extra import (
api_controller,
http_get,
)
from tenant.models.user import UserStubPhoneNumber
api = NinjaAPI()
class PhoneNumberSchema(ModelSchema):
class Meta:
model = UserStubPhoneNumber
fields = ["dial_code", "phone_number"]
# Django Ninja Extra
@api_controller("/users", tags=["User"])
class UserAPI:
@http_get("/test", response=PhoneNumberSchema)
def test(self, request, payload: PhoneNumberSchema):
print(payload.dial_code)
# Django Ninja
@api.get("/test", response=PhoneNumberSchema)
def test(request, data: PhoneNumberSchema):
print(data.dial_code) Thank you very much 😃 |
Hi @Tragio here is an example how I worked around the problem: class UserBodySchema(ModelSchema):
if TYPE_CHECKING:
date: datetime_date
belly: Decimal
waist: Decimal
hip: Decimal
class Meta:
model = UserBody
fields = [
"date",
"belly",
"waist",
"hip",
] It's not perfect but it's working. |
Describe the bug
Hi there! 😃 When using a ModelSchema with a Meta class that defines the model and fields, the type checker does not recognize the fields defined in the Meta class.
Code Example
Pylance outputs:
However, if I do the following, I have no problems, but then I'm repeating code.
Not sure if there is a better way, or if I'm doing something wrong 🤔
Thank you for the incredible work and have an amazing new year 🚀
The text was updated successfully, but these errors were encountered: