-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
ObjectVars wrong _var_type #4269
Comments
@adhami3310 there might be a bug in the |
For one, you can do: MyState.obj.to(Obj).other_object.to(OtherObject).attribute I will investigate the possible .to bug |
You're correct in that I checked your PR, I don't see any unexpected behavior. The only case I would say is that we don't handle normal classes w/ serializers like base classes. Is it possible to use dataclasses in your case? The issue is that there are logic that pydantic classes and dataclasses provide to retrieve fields and such that would be missing from such a bare class. |
Yes, you are right, only base_type is not used, I cleaned it up here: #4271
With hacking, everything is possible. But I would rather prefer reflex supporting bare classes as much as possible.
I thought the only requirement was |
We can then try to do that. So we should basically also handle bare classes with serializers. Can you either edit this issue or create a new one with specifically that info? |
That would be awesome! Just to clarify: While not documented, this all worked flawless before the var refactor, that's why I am raising a bug instead of a feature request. Btw: I just added some failing typing tests in my PR (#4268) as well. I think we can improve this with generics in the |
Next btw: OBJECT_TYPE = TypeVar("OBJECT_TYPE", bound=Dict) It seems like Edit: @adhami3310 wdyt about this cd7214a ? |
half intended, it's sth i long wanted to fix just not bothered enough to do, but yea there should be no bounds for OBJECT_TYPE
Some overloads only include generic in return, which doesn't make much sense, but i see improvement on some ends, although generally speaking, you're not gaining much from specifying to the static typing what kind of object var it is because we cannot give static typing of wrapped classes anyways |
Describe the bug
ObjectVars are often not automatically detected. Even if they are, the
_var_type
often ends up being aObjectVar[dict]
instead of the actual type.For example if you want to access a nested Object you currently often have to do smth like this:
Without
.to(ObjectVar)
attribute access ist completly blocked and without specifing the type, it often ends up being adict
which obviously does not have the same annotations as the correct type.I once create a draft PR (#3911) to at least improve the situation for
guess_type
. But that is not sufficient, there are many more places where this needs improvement.To Reproduce
I added some tests to showcase this: #4268
Expected behavior
Reflex is able to handle arbitrary objects with a serializer defined without ToOperations everywhere.
Screenshots
Specifics (please complete the following information):
Additional context
The text was updated successfully, but these errors were encountered: