-
Notifications
You must be signed in to change notification settings - Fork 343
Description
Note: I am using restx's Namespace for the following:
For request payload validation, I have something like this:
@ns.route('/event')
class EventResource(Resource):
@ns.expect(event_model, validate=True)
def post(self):
validated_data = ns.payload # Use the payload directly from the request
logger.info(f"Validated event data: {validated_data}")
...
For the model, I have a nested model like this:
event_department_model = ns.model('EventDepartment', {
'identifier': fields.String(required=True, description='Department identifier'),
'name': fields.String(required=True, description='Department name')
})
event_model = ns.model('Event', {
...
'department': fields.Nested(event_department_model, required=False, allow_null=True, skip_none=True, nullable=True, description='Department information'),
...
}
I want department in the input JSON payload to accept a department object(dictionary) or null. In event_model, I have already tried required=False, allow_null=True, nullable=True, skip_none=True and different combinations of these options, but nothing seems to be letting department accepting null.
However, no matter what combinations I have tried, I am getting the same error:
{
"errors": {
"department": "None is not of type 'object'"
},
"message": "Input payload validation failed"
}
Expected Behavior
It should accept the department property as being null
Actual Behavior
Getting error message of "None is not of type 'object'"
Error Messages/Stack Trace
{
"errors": {
"department": "None is not of type 'object'"
},
"message": "Input payload validation failed"
}
Environment
- Python version 3.12.2
- Flask version 3.1
- Flask-RESTX version 1.3
- Other installed Flask extensions
- Flask-SQLAlchemy
- Flask-Mail
- Flask-Limiter
- Flask-Session
- python-dotenv
- mysql-connector-python
Additional Context
I have already tried required=False, allow_null=True, nullable=True, skip_none=True and different combinations of these options but it did not work for me.