-
Notifications
You must be signed in to change notification settings - Fork 420
Feature request: Improve error message when parser fails #3580
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks for opening your first issue here! We'll come back to you as soon as we can. |
Looking at this now.. |
Hi @Mavtti! Thanks for opening this issue to report a possible bug. Just to confirm my suspicion: your However, I think there is room for us to improve our error message, as it leads us to believe that it is a problem with the Envelope and not the Model. What do you think about sending a PR and improving the error message? Thanks Example of code that worksfrom aws_lambda_powertools.utilities.parser import envelopes
from aws_lambda_powertools.utilities.parser.models import KinesisDataStreamModel
from aws_lambda_powertools.utilities.parser import event_parser
from aws_lambda_powertools.utilities.typing import LambdaContext
from pydantic import BaseModel
class SuggestionPayload(BaseModel):
message: str
username: str
@event_parser(model=SuggestionPayload, envelope=envelopes.KinesisDataStreamEnvelope)
def lambda_handler(document_events: KinesisDataStreamModel, _: LambdaContext):
print(document_events) Payload{
"Records": [
{
"kinesis": {
"kinesisSchemaVersion": "1.0",
"partitionKey": "1",
"sequenceNumber": "49590338271490256608559692538361571095921575989136588898",
"data": "eyJtZXNzYWdlIjogInRlc3QgbWVzc2FnZSIsICJ1c2VybmFtZSI6ICJ0ZXN0In0=",
"approximateArrivalTimestamp": 1545084650.987
},
"eventSource": "aws:kinesis",
"eventVersion": "1.0",
"eventID": "shardId-000000000006:49590338271490256608559692538361571095921575989136588898",
"eventName": "aws:kinesis:record",
"invokeIdentityArn": "arn:aws:iam::123456789012:role/lambda-role",
"awsRegion": "us-east-2",
"eventSourceARN": "arn:aws:kinesis:us-east-2:123456789012:stream/lambda-stream"
}
]
} data field decodedecho eyJtZXNzYWdlIjogInRlc3QgbWVzc2FnZSIsICJ1c2VybmFtZSI6ICJ0ZXN0In0= |base64 -di
{"message": "test message", "username": "test"} |
Hey @leandrodamascena thank for looking into it. Actually my SuggestionPayload does inherit from Here is a sample: from pydantic import BaseModel
from .document import Document
class SuggestionPayload(BaseModel):
arrived_at: Optional[str | int | float]
data: Document
operation: str And the subclass Document also inherit from BaseModel. I've tried using: |
Hi @Mavtti! Sorry to hear this, but in all my attempts here I could not reproduce the error. I am interested in understanding what is going wrong and fixing it. Thank you |
Hey @leandrodamascena in the end I've been able to reproduce on my side. You were right on the displayed error message, it hides the real issue. For my case it came from an AttributeError on the SuggestionPayload class. And this AttributeError was catched by the try/except. If it was any other error it would have been more explicit. Thx for the help. |
Hey @Mavtti! Nice to hear you could figure out this. I sent a PullRequest to improve the error message and make it more clear. Thanks again for taking the time to help us improve the developer experience. I will give you credits when I release a version with this fix. |
|
This is now released under 2.31.0 version! |
Expected Behaviour
I would expect it to work out of the box
Current Behaviour
I've wrapped my function with
event_parser
for a kinesis input. For some records and not all, I get the following error:I've tested to manually call
KinesisDataStreamEnvelope.parse
and it works fine.Strange thing, it doesn't happen for every lambda invocation.
Thx
Code snippet
Possible Solution
No response
Steps to Reproduce
Lambda with Kinesis data stream connector and the previous code snippet.
Lambda is in a Docker format and not zip.
Powertools for AWS Lambda (Python) version
latest
AWS Lambda function runtime
3.10
Packaging format used
PyPi
Debugging logs
The text was updated successfully, but these errors were encountered: