Améliore partition_remove_etud en cas d'accès concurrents

This commit is contained in:
Emmanuel Viennet 2023-07-13 20:01:42 +02:00
parent c933f010d4
commit 8ee95cc2e5

View File

@ -12,6 +12,7 @@ from operator import attrgetter
from flask import g, request from flask import g, request
from flask_json import as_json from flask_json import as_json
from flask_login import login_required from flask_login import login_required
import sqlalchemy as sa
from sqlalchemy.exc import IntegrityError from sqlalchemy.exc import IntegrityError
import app import app
@ -248,18 +249,24 @@ def partition_remove_etud(partition_id: int, etudid: int):
partition = query.first_or_404() partition = query.first_or_404()
if not partition.formsemestre.etat: if not partition.formsemestre.etat:
return json_error(403, "formsemestre verrouillé") return json_error(403, "formsemestre verrouillé")
groups = (
GroupDescr.query.filter_by(partition_id=partition_id) db.session.execute(
.join(group_membership) sa.text(
.filter_by(etudid=etudid) """DELETE FROM group_membership
WHERE etudid=:etudid
and group_id IN (
SELECT id FROM group_descr WHERE partition_id = :partition_id
);
"""
),
{"etudid": etudid, "partition_id": partition_id},
) )
for group in groups:
group.etuds.remove(etud)
Scolog.logdb( Scolog.logdb(
method="partition_remove_etud", method="partition_remove_etud",
etudid=etud.id, etudid=etud.id,
msg=f"Retrait du groupe {group.group_name} de {group.partition.partition_name}", msg=f"Retrait de la partition {partition.partition_name}",
commit=True, commit=False,
) )
db.session.commit() db.session.commit()
# Update parcours # Update parcours