1
- import re
2
1
from datetime import datetime
3
2
from typing import Dict , List , Optional
4
3
5
- from pydantic import BaseModel , root_validator , validator
4
+ from pydantic import BaseModel
6
5
from typing_extensions import Literal
7
6
8
7
@@ -24,28 +23,29 @@ class SqsMsgAttributeSchema(BaseModel):
24
23
binaryListValues : List [str ] = []
25
24
dataType : str
26
25
26
+ # context on why it's commented: https://github.com/awslabs/aws-lambda-powertools-python/pull/118
27
27
# Amazon SQS supports the logical data types String, Number, and Binary with optional custom data type
28
28
# labels with the format .custom-data-type.
29
29
# 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
49
49
50
50
51
51
class SqsRecordSchema (BaseModel ):
0 commit comments