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

raise HTTP 400 on IntegrityError during Clone #862

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion dispatcher/backend/src/routes/schedules/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,9 @@ def post(self, schedule_name: str, token: AccessToken.Payload, session: so.Sessi
)
clone.durations.append(duration)

session.flush()
try:
session.flush()
except IntegrityError:
raise BadRequest("Schedule name already exists")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find this a bit risky, I'm afraid we might have other integrity constraints in the future and might forget to alter this message.

At least I would log a warning with the exact integrity issue so that we can discover this in the log, otherwise it will be difficult to debug.

Or I would analyze IntegrityError, check the issue is about the schedule name, raise this BadRequest only in this situation ; and raise a more generic IntegrityError for other situations (which do not exist today).


return make_response(jsonify({"_id": str(clone.id)}), HTTPStatus.CREATED)