-
Notifications
You must be signed in to change notification settings - Fork 50
Description
Issue: Support for selective field updates in update_user methods
Description
The current update_user() methods in both sync (user.py) and async (async_main.py) implementations do not support the columns parameter, which prevents selective field updates. This is particularly problematic when trying to update specific fields like roles without affecting other user attributes.
Current Behavior
# Current implementation only allows updating all fields
sdk.update_user(user)This sends all user fields to the API, which can:
- Overwrite unintended fields
- Cause synchronization issues when multiple processes update different fields
- Not leverage Casdoor's API support for selective updates via the
columnsparameter
Expected Behavior
# Should support selective field updates
sdk.update_user(user, columns=['roles'])
sdk.update_user(user, columns=['roles', 'email'])This would send ?columns=roles or ?columns=roles,email as query parameters to the Casdoor API endpoint /api/update-user, allowing granular control over which fields are updated.
Use Case
When implementing role auto-assignment for new users:
- Fetch user from Casdoor
- Add role to user.roles list
- Update only the roles field without touching other fields like email, phone, etc.
Currently, this workflow fails or causes unintended side effects because all fields are sent in the update request.
Proposed Solution
Add an optional columns parameter to:
update_user(user: User, columns: Optional[List[str]] = None)update_user_by_id(id: str, user: User, columns: Optional[List[str]] = None)modify_user(method: str, user: User, columns: Optional[List[str]] = None)modify_user_by_id(method: str, id: str, user: User, columns: Optional[List[str]] = None)
Implementation
I have already implemented this feature in a fork and tested it. The implementation:
- ✅ Maintains backward compatibility (defaults to None = update all fields)
- ✅ Works with both sync and async versions
- ✅ Includes comprehensive docstrings
- ✅ Properly formats the columns as comma-separated query parameter
Pull Request
I will submit a PR with the implementation shortly.
Environment
- Python SDK version: Latest master
- Python version: 3.12+
- Casdoor server version: Compatible with columns parameter
Additional Context
The Casdoor API already supports the columns parameter for selective updates (documented in the Go SDK and API), but the Python SDK doesn't expose this functionality to users.