régler erreur 500 sur changement de role par admin
This commit is contained in:
+8
-3
@@ -112,14 +112,19 @@ def edit_user(user_id):
|
||||
discord_user_id = request.form.get('discord_user_id', '').strip()
|
||||
league_os_profile = request.form.get('league_os_profile', '').strip()
|
||||
|
||||
# Change role via raw SQL to avoid polymorphic identity corruption
|
||||
# Change role via raw SQL to avoid polymorphic identity corruption.
|
||||
# Must discard the entire session because the polymorphic discriminator
|
||||
# change invalidates the identity map for this instance and anything
|
||||
# that references it via relationships.
|
||||
if user.role != role:
|
||||
user_id_local = user.id
|
||||
db.session.execute(
|
||||
db.text("UPDATE users SET role = :role WHERE id = :id"),
|
||||
{"role": role, "id": user.id}
|
||||
{"role": role, "id": user_id_local}
|
||||
)
|
||||
db.session.commit()
|
||||
user = User.query.get(user_id) # re-fetch with correct polymorphic class
|
||||
db.session.remove() # discard stale session entirely
|
||||
user = User.query.get(user_id_local) # fresh session, correct class
|
||||
|
||||
user.full_name = full_name
|
||||
user.email = email
|
||||
|
||||
Reference in New Issue
Block a user