From d0e8e8b2d179bf3895322eb83b28f542f0e1f242 Mon Sep 17 00:00:00 2001 From: "zhenyu (Eric) Liu" <102937168+ericinfins@users.noreply.github.com> Date: Thu, 19 Jan 2023 11:11:51 +1100 Subject: [PATCH] Update utils.py Fix the error: TypeError: object of type 'NoneType' has no len() --- rest_framework_json_api/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rest_framework_json_api/utils.py b/rest_framework_json_api/utils.py index c9114128..d67422ee 100644 --- a/rest_framework_json_api/utils.py +++ b/rest_framework_json_api/utils.py @@ -461,6 +461,6 @@ def format_error_object(message, pointer, response): def format_errors(data): - if len(data) > 1 and isinstance(data, list): + if isinstance(data, list) and len(data) > 1: data.sort(key=lambda x: x.get("source", {}).get("pointer", "")) return {"errors": data}