You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is a performance downgrade introduced in #19 .
Due to the inheritance of JokeSingleSubmit + the workflow of using JokeBase to match the joke type, "type" and "category" are validated twice in the submit pipeline.
The text was updated successfully, but these errors were encountered:
After investigating the pydantic docs, it doesn't seem there's a possibility to skip only certain fields. Pydantic does offer a construct method on all models that inherit from BaseModel but simply creates the model without any validation.
It is possible to delay the validation until the JokeSingleSubmit is called by using the construct method to build the joke base. So something like
joke=JokeBase.construct(**data)
However, this would make the use of match_type less safe since the type hasn't been validated at this point. If the type is not valid, the method can raise a key error when converting the string to an enum in Type[self.type].
Of course, the type should never be invalid since it's coming directly from click which also checks that the input is valid 🤷♂️ Also the method is wrapped inside a @safe decorator, so even it if fails, it won't display anything to the user unless the debug flag is activated.
All in all, if we want to improve the performance slightly, while also having plenty of safety checks in place, we could simply use the construct method as mentioned above and delay the validation until the JokeSingleSubmit or JokeTwopartSubmit models are created.
There is a performance downgrade introduced in #19 .
Due to the inheritance of
JokeSingleSubmit
+ the workflow of usingJokeBase
to match the joke type, "type" and "category" are validated twice in the submit pipeline.The text was updated successfully, but these errors were encountered: