Events: put_events() now throws a warning when Detail field is not a dict (#6875)
This commit is contained in:
parent
9767f0226d
commit
f5a69d531d
@ -1327,7 +1327,11 @@ class EventsBackend(BaseBackend):
|
||||
)
|
||||
else:
|
||||
try:
|
||||
json.loads(event["Detail"])
|
||||
detail = json.loads(event["Detail"])
|
||||
if not isinstance(detail, dict):
|
||||
warnings.warn(
|
||||
f"EventDetail should be of type dict - types such as {type(detail)} are ignored by AWS"
|
||||
)
|
||||
except ValueError: # json.JSONDecodeError exists since Python 3.5
|
||||
entries.append(
|
||||
{
|
||||
|
@ -1,13 +1,14 @@
|
||||
import json
|
||||
import random
|
||||
import unittest
|
||||
import warnings
|
||||
from datetime import datetime, timezone
|
||||
|
||||
import boto3
|
||||
import pytest
|
||||
from botocore.exceptions import ClientError
|
||||
|
||||
from moto import mock_logs
|
||||
from moto import mock_logs, settings
|
||||
from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID
|
||||
from moto.core.utils import iso_8601_datetime_without_milliseconds
|
||||
from moto.events import mock_events
|
||||
@ -682,6 +683,12 @@ def test_put_events():
|
||||
assert response["FailedEntryCount"] == 0
|
||||
assert len(response["Entries"]) == 1
|
||||
|
||||
if settings.TEST_DECORATOR_MODE:
|
||||
event["Detail"] = json.dumps([{"Key": "k", "Value": "v"}])
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
client.put_events(Entries=[event])
|
||||
assert "EventDetail should be of type dict" in str(w[0].message)
|
||||
|
||||
|
||||
@mock_events
|
||||
def test_put_events_error_too_many_entries():
|
||||
|
Loading…
Reference in New Issue
Block a user