Skip to content

Commit 8539002

Browse files
committed
fix: comment out validators #118
1 parent 585f708 commit 8539002

File tree

2 files changed

+30
-29
lines changed

2 files changed

+30
-29
lines changed

aws_lambda_powertools/utilities/advanced_parser/schemas/dynamodb.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from datetime import date
22
from typing import Any, Dict, List, Optional
33

4-
from pydantic import BaseModel, root_validator
4+
from pydantic import BaseModel
55
from typing_extensions import Literal
66

77

@@ -14,15 +14,16 @@ class DynamoScheme(BaseModel):
1414
SizeBytes: int
1515
StreamViewType: Literal["NEW_AND_OLD_IMAGES", "KEYS_ONLY", "NEW_IMAGE", "OLD_IMAGE"]
1616

17+
# context on why it's commented: https://github.com/awslabs/aws-lambda-powertools-python/pull/118
1718
# since both images are optional, they can both be None. However, at least one must
1819
# exist in a legal schema of NEW_AND_OLD_IMAGES type
19-
@root_validator
20-
def check_one_image_exists(cls, values):
21-
new_img, old_img = values.get("NewImage"), values.get("OldImage")
22-
stream_type = values.get("StreamViewType")
23-
if stream_type == "NEW_AND_OLD_IMAGES" and not new_img and not old_img:
24-
raise TypeError("DynamoDB streams schema failed validation, missing both new & old stream images")
25-
return values
20+
# @root_validator
21+
# def check_one_image_exists(cls, values): # noqa: E800
22+
# new_img, old_img = values.get("NewImage"), values.get("OldImage") # noqa: E800
23+
# stream_type = values.get("StreamViewType") # noqa: E800
24+
# if stream_type == "NEW_AND_OLD_IMAGES" and not new_img and not old_img: # noqa: E800
25+
# raise TypeError("DynamoDB streams schema failed validation, missing both new & old stream images") # noqa: E800,E501
26+
# return values # noqa: E800
2627

2728

2829
class UserIdentity(BaseModel):

aws_lambda_powertools/utilities/advanced_parser/schemas/sqs.py

+21-21
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import re
21
from datetime import datetime
32
from typing import Dict, List, Optional
43

5-
from pydantic import BaseModel, root_validator, validator
4+
from pydantic import BaseModel
65
from typing_extensions import Literal
76

87

@@ -24,28 +23,29 @@ class SqsMsgAttributeSchema(BaseModel):
2423
binaryListValues: List[str] = []
2524
dataType: str
2625

26+
# context on why it's commented: https://github.com/awslabs/aws-lambda-powertools-python/pull/118
2727
# Amazon SQS supports the logical data types String, Number, and Binary with optional custom data type
2828
# labels with the format .custom-data-type.
2929
# https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-message-metadata.html#sqs-message-attributes
30-
@validator("dataType")
31-
def valid_type(cls, v): # noqa: VNE001
32-
pattern = re.compile("Number.*|String.*|Binary.*")
33-
if not pattern.match(v):
34-
raise TypeError("data type is invalid")
35-
return v
36-
37-
# validate that dataType and value are not None and match
38-
@root_validator
39-
def check_str_and_binary_values(cls, values):
40-
binary_val, str_val = values.get("binaryValue", ""), values.get("stringValue", "")
41-
data_type = values.get("dataType")
42-
if not str_val and not binary_val:
43-
raise TypeError("both binaryValue and stringValue are missing")
44-
if data_type.startswith("Binary") and not binary_val:
45-
raise TypeError("binaryValue is missing")
46-
if (data_type.startswith("String") or data_type.startswith("Number")) and not str_val:
47-
raise TypeError("stringValue is missing")
48-
return values
30+
# @validator("dataType")
31+
# def valid_type(cls, v): # noqa: VNE001,E800 # noqa: E800
32+
# pattern = re.compile("Number.*|String.*|Binary.*") # noqa: E800
33+
# if not pattern.match(v): # noqa: E800
34+
# raise TypeError("data type is invalid") # noqa: E800
35+
# return v # noqa: E800
36+
#
37+
# # validate that dataType and value are not None and match
38+
# @root_validator
39+
# def check_str_and_binary_values(cls, values): # noqa: E800
40+
# binary_val, str_val = values.get("binaryValue", ""), values.get("stringValue", "") # noqa: E800
41+
# data_type = values.get("dataType") # noqa: E800
42+
# if not str_val and not binary_val: # noqa: E800
43+
# raise TypeError("both binaryValue and stringValue are missing") # noqa: E800
44+
# if data_type.startswith("Binary") and not binary_val: # noqa: E800
45+
# raise TypeError("binaryValue is missing") # noqa: E800
46+
# if (data_type.startswith("String") or data_type.startswith("Number")) and not str_val: # noqa: E800
47+
# raise TypeError("stringValue is missing") # noqa: E800
48+
# return values # noqa: E800
4949

5050

5151
class SqsRecordSchema(BaseModel):

0 commit comments

Comments
 (0)