-
Notifications
You must be signed in to change notification settings - Fork 397
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
Validator: Date-time format fails validation #496
Comments
Thanks for opening your first issue here! We'll come back to you as soon as we can. |
Hey @j2clerck Thanks for raising this - I've just managed to reproduce by re-adding the Full snippet to reproduce from aws_lambda_powertools.utilities.validation import validate
schema = {
"$schema": "http://json-schema.org/draft-07/schema",
"type": "object",
"required": ["eventType"],
"properties": {
"eventType": {
"$id": "#/properties/eventType",
"type": "string",
"pattern": "com.okta.event_hook",
},
"eventTypeVersion": {
"$id": "#/properties/eventTypeVersion",
"type": "string",
},
"cloudEventsVersion": {
"$id": "#/properties/cloudEventsVersion",
"type": "string",
},
"contentType": {
"$id": "#/properties/contentType",
"type": "string",
},
"eventId": {
"$id": "#/properties/eventId",
"type": "string",
},
"data": {
"$id": "#/properties/data",
"type": "object",
"required": ["events"],
"properties": {
"events": {
"type": "array",
"items": {"type": "object"},
"properties": {
"published": {
"id": "#/properties/data/events/published",
"type": "string",
"format": "date-time"
}
}
}
},
},
},
}
raw_event = {
"eventType": "com.okta.event_hook",
"eventTypeVersion": "1.0",
"cloudEventsVersion": "0.1",
"source": "https://dev-XXXXXX.okta.com/api/v1/eventHooks/XXXXXXX",
"eventId": "c9ad0d85-1ce9-4dfe-996c-8e5441214189",
"data": {
"events": [
{
"uuid": "242dbb7a-d50d-11eb-9787-79648ebc0d8c",
"published": "2021-06-24T16:56:38.320Z",
"eventType": "group.user_membership.add",
"version": "0",
"displayMessage": "Add user to group membership",
"severity": "INFO",
"client": {
"userAgent": "",
"zone": "",
"device": "",
"id": "",
"ipAddress": "",
"geographicalContext": "",
"ipChain": []
},
"device": "",
"actor": {
"id": "",
"type": "User",
"alternateId": "[email protected]",
"displayName": "John Doe",
"detailEntry": ""
},
"outcome": {
"result": "SUCCESS",
"reason": ""
},
"target": [
{
"id": "",
"type": "User",
"alternateId": "[email protected]",
"displayName": "John Doe",
"detailEntry": ""
},
{
"id": "00ga8rdpafWMUl69l357",
"type": "UserGroup",
"alternateId": "unknown",
"displayName": "SomeGroup",
"detailEntry": ""
}
],
"transaction": {
"type": "JOB",
"id": "gwja8rfhsaVSZvTn9357",
"detail": {}
},
"debugContext": {
"debugData": {}
},
"legacyEventType": "core.user_group_member.user_add",
"authenticationContext": {
"authenticationProvider": "",
"credentialProvider": "",
"credentialType": "",
"issuer": "",
"authenticationStep": 0,
"externalSessionId": "",
"interface": ""
},
"securityContext": {
"asNumber": "",
"asOrg": "",
"isp": "",
"domain": "",
"isProxy": ""
},
"insertionTimestamp": ""
}
]
},
"eventTime": "2021-06-29T14:46:06.804Z",
"contentType": "application/json"
}
validate(event=raw_event, schema=schema) |
PR created - will merge as soon as CI checks pass. I took a look upstream to further investigate |
Staging this for the next release - As there's a workaround ( |
What were you trying to accomplish?
I am trying to validate an event against a json schema using the validate function.
validate(event=json_payload, schema=INPUT)
Expected Behavior
I expected the schema to be validated correctly.
Current Behavior
The validate function is raising the following error:
Error: argument of type 'NoneType' is not iterable
Possible Solution
Instead of using a default value of None for formats, formats should be an empty dict.
It seems the issues comes from fastjsonschema not handling custom format date-time in the schema. According from fastjsonschema repo the issues is fixed. It might be because the validate function set the formats to None whereas fastjsonschema.validate function sets the formats to an empty dict.
Steps to Reproduce (for bugs)
Environment
# paste logs here
Some links:
horejsek/python-fastjsonschema#115
Schema example
event example:
The text was updated successfully, but these errors were encountered: