-
Notifications
You must be signed in to change notification settings - Fork 407
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(parser): fallback to
validate_python
when using type[Model]
a…
…nd nested models (#5313) * Fix Pydantic limitation * Add e2e tests * Reverting change in e2e layer
- Loading branch information
1 parent
b271c17
commit fe6b335
Showing
6 changed files
with
138 additions
and
16 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
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
23 changes: 23 additions & 0 deletions
23
tests/e2e/parser/handlers/handler_with_model_type_class.py
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,23 @@ | ||
import json | ||
from typing import Any, Dict, Type, Union | ||
|
||
from pydantic import BaseModel | ||
|
||
from aws_lambda_powertools.utilities.parser import parse | ||
from aws_lambda_powertools.utilities.typing import LambdaContext | ||
|
||
AnyInheritedModel = Union[Type[BaseModel], BaseModel] | ||
RawDictOrModel = Union[Dict[str, Any], AnyInheritedModel] | ||
|
||
|
||
class ModelWithUnionType(BaseModel): | ||
name: str | ||
profile: RawDictOrModel | ||
|
||
|
||
def lambda_handler(event: ModelWithUnionType, context: LambdaContext): | ||
event = json.dumps(event) | ||
|
||
event_parsed = parse(event=event, model=ModelWithUnionType) | ||
|
||
return {"name": event_parsed.name} |
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