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

Stephan/fix/last deployment #615

Merged
merged 1 commit into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
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
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
Loading