Skip to content
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

API 更新用户资源组会抛异常 #1775

Closed
majingpu opened this issue Aug 15, 2022 · 0 comments · Fixed by #1776
Closed

API 更新用户资源组会抛异常 #1775

majingpu opened this issue Aug 15, 2022 · 0 comments · Fixed by #1776

Comments

@majingpu
Copy link

重现步骤

通过api接口更新用户信息失败:

uri:`/api/v1/user/2/` method:`put`
request:
{
    "password":"ma19970423",
    "is_superuser": true,
    "username": "jingpu.ma",
    "email": "demo@leyantech.com",
    "is_staff": false,
    "is_active": true,
    "display": "马净璞",
    "failed_login_count": 0,
    "groups": [3],
    "user_permissions": [],
    "resource_group": [1]
}

image

预期外的结果

报错:

Internal Server Error: /api/v1/user/2/
Traceback (most recent call last):
  File "/Users/leyan-noc/Desktop/pythonProject/Archery/venv/lib/python3.9/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
  File "/Users/leyan-noc/Desktop/pythonProject/Archery/venv/lib/python3.9/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/Users/leyan-noc/Desktop/pythonProject/Archery/venv/lib/python3.9/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "/Users/leyan-noc/Desktop/pythonProject/Archery/venv/lib/python3.9/site-packages/django/views/generic/base.py", line 84, in view
    return self.dispatch(request, *args, **kwargs)
  File "/Users/leyan-noc/Desktop/pythonProject/Archery/venv/lib/python3.9/site-packages/rest_framework/views.py", line 509, in dispatch
    response = self.handle_exception(exc)
  File "/Users/leyan-noc/Desktop/pythonProject/Archery/venv/lib/python3.9/site-packages/rest_framework/views.py", line 469, in handle_exception
    self.raise_uncaught_exception(exc)
  File "/Users/leyan-noc/Desktop/pythonProject/Archery/venv/lib/python3.9/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
    raise exc
  File "/Users/leyan-noc/Desktop/pythonProject/Archery/venv/lib/python3.9/site-packages/rest_framework/views.py", line 506, in dispatch
    response = handler(request, *args, **kwargs)
  File "/Users/leyan-noc/Desktop/pythonProject/Archery/sql_api/api_user.py", line 90, in put
    serializer.save()
  File "/Users/leyan-noc/Desktop/pythonProject/Archery/venv/lib/python3.9/site-packages/rest_framework/serializers.py", line 207, in save
    self.instance = self.update(self.instance, validated_data)
  File "/Users/leyan-noc/Desktop/pythonProject/Archery/sql_api/serializers.py", line 57, in update
    setattr(instance, attr, value)
  File "/Users/leyan-noc/Desktop/pythonProject/Archery/venv/lib/python3.9/site-packages/django/db/models/fields/related_descriptors.py", line 595, in __set__
    raise TypeError(
TypeError: Direct assignment to the forward side of a many-to-many set is prohibited. Use groups.set() instead.
[15/Aug/2022 17:21:07] "PUT /api/v1/user/2/ HTTP/1.0" 500 15459

日志文本

No response

版本

1.8.5

部署方式

手工部署

是否还有其他可以辅助定位问题的信息?比如数据库版本等

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant