Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
fixed not checking for tuple type anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerwoud committed Mar 11, 2024
1 parent c5e3bc4 commit 5c6a28d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion backend/project/endpoints/projects/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def post(self):
"course_id",
"visible_for_students",
"archieved"]
)
)[0]

project_upload_directory = os.path.join(f"{UPLOAD_FOLDER}", f"{new_project.project_id}")

Expand Down
14 changes: 8 additions & 6 deletions backend/project/utils/query_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def create_model_instance(model: DeclarativeMeta,
db.session.add(new_instance)
db.session.commit()

return new_instance
return new_instance, 201


def insert_into_model(model: DeclarativeMeta,
Expand All @@ -95,18 +95,20 @@ def insert_into_model(model: DeclarativeMeta,
"""
try:
new_instance = create_model_instance(model, data, response_url_base, required_fields)
model_instance = new_instance[0]
status_code = new_instance[1]
# if its a tuple the model instance couldn't be created so it already
# is the right format of error message and we just need to return
if isinstance(new_instance, tuple):
return new_instance
if status_code == 400:
return model_instance, status_code

return (jsonify({
"data": new_instance,
"data": model_instance,
"message": "Object created succesfully.",
"url":
urljoin(response_url_base + "/",
str(getattr(new_instance, url_id_field)))}),
201)
str(getattr(model_instance, url_id_field)))}),
status_code)
except SQLAlchemyError:
db.session.rollback()
return jsonify({"error": "Something went wrong while inserting into the database.",
Expand Down

0 comments on commit 5c6a28d

Please sign in to comment.