-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove parser, opt for using model in simpler way
- Loading branch information
Showing
5 changed files
with
52 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from typing import TypeVar, Type, Generic | ||
|
||
from pydantic import BaseModel, ValidationError | ||
|
||
from rest_framework.exceptions import ParseError | ||
|
||
T = TypeVar("T", bound=BaseModel) | ||
|
||
|
||
class PydanticModelMixin(Generic[T]): | ||
def get_model(self, data: dict, model: Type[T]) -> T: | ||
try: | ||
return model.model_validate(data) | ||
except ValidationError as exc: | ||
raise ParseError("JSON parse error - %s" % str(exc)) | ||
Check warning Code scanning / CodeQL Information exposure through an exception Medium Stack trace information Error loading related location Loading |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters