Fix exception occuring on Admin demotion (#1799)

* Fix an exception that occurred when demoting an Admin user
* Fix the response from the above request from returning a list instead of a dict
* Closes #1794
This commit is contained in:
Kevin Chung
2021-02-09 04:03:04 -05:00
committed by GitHub
parent 0a5a886ac6
commit fa7316722e
3 changed files with 28 additions and 6 deletions

View File

@@ -233,16 +233,18 @@ class UserPublic(Resource):
if response.errors:
return {"success": False, "errors": response.errors}, 400
db.session.commit()
# This generates the response first before actually changing the type
# This avoids an error during User type changes where we change
# the polymorphic identity resulting in an ObjectDeletedError
# https://github.com/CTFd/CTFd/issues/1794
response = schema.dump(response.data)
db.session.commit()
db.session.close()
clear_user_session(user_id=user_id)
clear_standings()
return {"success": True, "data": response}
return {"success": True, "data": response.data}
@admins_only
@users_namespace.doc(