-
Notifications
You must be signed in to change notification settings - Fork 9
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
pydantic2.0 #168
pydantic2.0 #168
Conversation
… using the 'singledispatchmethod' decorator
|
||
from .database import DBContextStorage, threadsafe_method | ||
from dff.script import Context | ||
|
||
|
||
class SerializableStorage(BaseModel, extra=Extra.allow): | ||
@root_validator | ||
class SerializableStorage(BaseModel, extra="allow"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not directly related to pydantic 2.0, but why is this storage implemented using this class?
Seems like the only use is to cast all values in loaded json file to Context
but can't we just do that inside the _load
method?
If not, this class should be documented and defined inside the JSONContextStorage
class.
Previously this issue wasn't that evident, but now code like len(self.storage.model_extra)
looks weird.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No idea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that changes to this class are necessary, since it's going to be replaced by the new context storage implementation
elif not issubclass(type(ctx), Context): | ||
raise ValueError( | ||
f"context expected as sub class of Context class or object of dict/str(json) type, but got {ctx}" | ||
) | ||
return ctx | ||
|
||
@validate_arguments |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the status on the pickling issue?
Is it going to be fixed in #93?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
validating arguments is not needed now, we can parse the argument inside the function body
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can but that is not how we are supposed to work with pydantic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my view, this strategy is better, since it does not modify the Context
model, while using validate_call
decorators leads to the Message
class being referenced in the Context class body which causes the pickling problems
normalize_label, | ||
normalize_condition, | ||
normalize_transitions, | ||
normalize_response, | ||
normalize_processing, | ||
normalize_script, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not related to the PR, but:
Why import these functions if they are not supposed to be used by the user?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR seems good but
There are still three comments left that are unrelated to this PR:
- pydantic2.0 #168 (comment) -- question about json storage for @pseusys
- pydantic2.0 #168 (comment) -- question about context pickling (why do we pickle all methods of the context class and is this behavior going to be changed) for @pseusys
- pydantic2.0 #168 (comment) -- question about function imports for @kudep
elif not issubclass(type(ctx), Context): | ||
raise ValueError( | ||
f"context expected as sub class of Context class or object of dict/str(json) type, but got {ctx}" | ||
) | ||
return ctx | ||
|
||
@validate_arguments |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can but that is not how we are supposed to work with pydantic.
Speaking of the comment:
|
"now" means in #93? I'm assuming this PR will be merged before that one, so I think we should return |
Yes, "now" means in #93. |
Previously it was Or do you mean that we shouldn't use any type validation? I don't think we should do that. Type validation would help in case a user would accidentally write a function that sets |
I only meant that I don't think there should be any concerns about pickling while reasoning about validating arguments. |
Description
Use pydantic 2.0
Checklist