Skip to content

Fix error message in upsert action #6918

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

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
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ def upsert(self, model: BaseDBModel, return_json: bool = True) -> Response:
Response: Contains status, message and data (either dict or SQLModel based on return_json)
"""
status = True
status_message = ""
model_class = type(model)
existing_model = None

Expand All @@ -194,13 +195,16 @@ def upsert(self, model: BaseDBModel, return_json: bool = True) -> Response:
session.rollback()
logger.error("Error while updating/creating " + str(model_class.__name__) + ": " + str(e))
status = False
status_message = f"Error while updating/creating {model_class.__name__}"
else:
status_message = (
f"{model_class.__name__} Updated Successfully"
if existing_model
else f"{model_class.__name__} Created Successfully"
)

return Response(
message=(
f"{model_class.__name__} Updated Successfully"
if existing_model
else f"{model_class.__name__} Created Successfully"
),
message=status_message,
status=status,
data=model.model_dump() if return_json else model,
)
Expand Down
Loading