Skip to content

Commit

Permalink
Fix DB fetching on not found entries
Browse files Browse the repository at this point in the history
Whenever a GET call to a non-existent object is requested, the server would
not return a proper `404` code response. Instead, it returned a `500`, because
`.to_dict()` was called upon the not found object directly (which should be
`None`). This patch makes sure that `.to_dict()` is only called upon existing
DB models, and as a result, it will return a `404` response on not found
objects.
  • Loading branch information
Dany9966 committed Oct 18, 2023
1 parent 64d86bf commit 5639314
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions coriolis/db/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from coriolis import exception
from coriolis import utils


CONF = cfg.CONF
db_options.set_defaults(CONF)

Expand Down Expand Up @@ -305,7 +306,7 @@ def get_replica_tasks_execution(context, replica_id, execution_id,
db_result = q.filter(
models.Replica.id == replica_id,
models.TasksExecution.id == execution_id).first()
if to_dict:
if to_dict and db_result is not None:
return db_result.to_dict()
return db_result

Expand Down Expand Up @@ -457,7 +458,7 @@ def get_replica(context, replica_id, include_task_info=False, to_dict=False):

replica = q.filter(
models.Replica.id == replica_id).first()
if to_dict:
if to_dict and replica is not None:
return replica.to_dict(include_task_info=include_task_info)

return replica
Expand Down Expand Up @@ -569,7 +570,7 @@ def get_migration(context, migration_id, include_task_info=False,
args["project_id"] = context.project_id
db_result = q.filter_by(**args).first()

if to_dict:
if to_dict and db_result is not None:
return db_result.to_dict(include_task_info=include_task_info)
return db_result

Expand Down

0 comments on commit 5639314

Please sign in to comment.