From d25b35c928c52cc5ec2a9e69305da2675b1044b9 Mon Sep 17 00:00:00 2001 From: cedrick2711 Date: Tue, 4 Aug 2026 22:06:43 -0400 Subject: [PATCH] =?UTF-8?q?r=C3=A9gler=20erreur=20500=20sur=20changement?= =?UTF-8?q?=20de=20role=20par=20admin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/routes/users.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/routes/users.py b/app/routes/users.py index 7167c3a..8cbe3cf 100644 --- a/app/routes/users.py +++ b/app/routes/users.py @@ -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