From 6336c574f8a70d230deed70fc271cfb12dbc41bc Mon Sep 17 00:00:00 2001 From: Paco Aranda Date: Wed, 30 Oct 2024 21:56:59 +0100 Subject: [PATCH] [BUGFIX] argilla server: Prevent update `dataset.updated_at` when updating `dataset.last_activity_at` column (#5656) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Description Closes # **Type of change** - Bug fix (non-breaking change which fixes an issue) **How Has This Been Tested** **Checklist** - I added relevant documentation - I followed the style guidelines of this project - I did a self-review of my code - I made corresponding changes to the documentation - I confirm My changes generate no new warnings - I have added tests that prove my fix is effective or that my feature works - I have added relevant notes to the CHANGELOG.md file (See https://keepachangelog.com/) --------- Co-authored-by: José Francisco Calvo --- argilla-server/CHANGELOG.md | 4 ++++ argilla-server/src/argilla_server/contexts/datasets.py | 7 ++++++- .../tests/unit/api/handlers/v1/test_responses.py | 2 ++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/argilla-server/CHANGELOG.md b/argilla-server/CHANGELOG.md index 9c385b82a2..d12224e627 100644 --- a/argilla-server/CHANGELOG.md +++ b/argilla-server/CHANGELOG.md @@ -16,6 +16,10 @@ These are the section headers that we use: ## [Unreleased]() +### Fixed + +- Fixed error so now `_touch_dataset_last_activity_at` function is not updating dataset's `updated_at` column. ([#5656](https://github.com/argilla-io/argilla/pull/5656)) + ## [2.4.0](https://github.com/argilla-io/argilla/compare/v2.3.1...v2.4.0) ### Added diff --git a/argilla-server/src/argilla_server/contexts/datasets.py b/argilla-server/src/argilla_server/contexts/datasets.py index 131904307b..b31aafe3b4 100644 --- a/argilla-server/src/argilla_server/contexts/datasets.py +++ b/argilla-server/src/argilla_server/contexts/datasets.py @@ -100,7 +100,12 @@ async def _touch_dataset_last_activity_at(db: AsyncSession, dataset: Dataset) -> None: await db.execute( - sqlalchemy.update(Dataset).where(Dataset.id == dataset.id).values(last_activity_at=datetime.utcnow()) + sqlalchemy.update(Dataset) + .where(Dataset.id == dataset.id) + .values( + last_activity_at=datetime.utcnow(), + updated_at=Dataset.__table__.c.updated_at, + ) ) diff --git a/argilla-server/tests/unit/api/handlers/v1/test_responses.py b/argilla-server/tests/unit/api/handlers/v1/test_responses.py index ceddf5201d..547e6faef4 100644 --- a/argilla-server/tests/unit/api/handlers/v1/test_responses.py +++ b/argilla-server/tests/unit/api/handlers/v1/test_responses.py @@ -102,6 +102,7 @@ async def test_update_response( "updated_at": datetime.fromisoformat(resp_body["updated_at"]).isoformat(), } + await db.refresh(dataset) assert dataset.last_activity_at > dataset_previous_last_activity_at assert dataset.updated_at == dataset_previous_updated_at @@ -421,6 +422,7 @@ async def test_delete_response( assert resp.status_code == 200 assert (await db.execute(select(func.count(Response.id)))).scalar() == 0 + await db.refresh(dataset) assert dataset.last_activity_at > dataset_previous_last_activity_at assert dataset.updated_at == dataset_previous_updated_at