From b59c856f294d21c3c14f9c9d67cf6c326830ef41 Mon Sep 17 00:00:00 2001 From: ytqh Date: Sun, 9 Mar 2025 20:53:57 +0800 Subject: [PATCH] bugfix: simplify major check logic --- .../service_api_with_auth/user/profile.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/api/controllers/service_api_with_auth/user/profile.py b/api/controllers/service_api_with_auth/user/profile.py index a7ae6ba930..3105f5fcdd 100644 --- a/api/controllers/service_api_with_auth/user/profile.py +++ b/api/controllers/service_api_with_auth/user/profile.py @@ -106,12 +106,15 @@ class UserProfile(Resource): if 'major' in data: major = data['major'] - if not isinstance(major, str): - return {"success": False, "message": "Major must be a string value"}, 400 - if len(major) > 50: + # Allow None as a valid value (to clear the field) + if major is None: + validated_data['major'] = None + elif not isinstance(major, str): + return {"success": False, "message": "Major must be a string value or null"}, 400 + elif len(major) > 50: return {"success": False, "message": "Major exceeds maximum length of 50"}, 400 - - validated_data['major'] = major + else: + validated_data['major'] = major # Use the service to update user profile success, error = EndUserService.update_user_profile(end_user, validated_data)