Skip to content

Commit

Permalink
fix: corrected get_last_deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
SteBaum committed Jul 26, 2024
1 parent 44be9b1 commit de8296e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
8 changes: 6 additions & 2 deletions tdp/dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from typing import Iterable, NamedTuple, Optional

from sqlalchemy import Engine, Select, and_, case, func, or_, select
from sqlalchemy import Engine, Select, and_, case, desc, func, or_, select
from sqlalchemy.orm import sessionmaker

from tdp.core.cluster_status import ClusterStatus
Expand Down Expand Up @@ -288,7 +288,11 @@ def get_planned_deployment(self) -> Optional[DeploymentModel]:
def get_last_deployment(self) -> Optional[DeploymentModel]:
"""Get the last deployment."""
self._check_session()
return self.session.query(DeploymentModel).order_by(DeploymentModel.id).first()
return (
self.session.query(DeploymentModel)
.order_by(desc(DeploymentModel.id))
.first()
)

def get_deployments(
self, limit: Optional[int] = None, offset: Optional[int] = None
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/test_dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,12 @@ def test_get_planned_deployment(db_engine):
@pytest.mark.parametrize("db_engine", [True], indirect=True)
def test_get_last_deployment(db_engine):
with create_session(db_engine) as session:
session.add(
DeploymentModel(
id=2,
state=DeploymentStateEnum.FAILURE,
)
)
session.add(
DeploymentModel(
id=3,
Expand Down

0 comments on commit de8296e

Please sign in to comment.