From 9276a4ca2e74ef5ae504be8387c8d03c1053daea Mon Sep 17 00:00:00 2001 From: David Manthey Date: Fri, 10 Nov 2023 08:50:08 -0500 Subject: [PATCH] Fix time comparison in annotation history check --- CHANGELOG.md | 1 + .../girder_large_image_annotation/models/annotation.py | 2 +- girder_annotation/test_annotation/test_annotations_rest.py | 7 +++++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 82404e561..85b8cc32e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ ### Bug Fixes - Default to "None" for the DICOM assetstore limit ([#1359](../../pull/1359)) - Fix series detection for some bioformats files ([#1365](../../pull/1365), [#1367](../../pull/1367)) +- Fix time comparison in annotation history check ([#1369](../../pull/1369)) ## 1.26.0 diff --git a/girder_annotation/girder_large_image_annotation/models/annotation.py b/girder_annotation/girder_large_image_annotation/models/annotation.py index 0173d91d3..527d3f58e 100644 --- a/girder_annotation/girder_large_image_annotation/models/annotation.py +++ b/girder_annotation/girder_large_image_annotation/models/annotation.py @@ -1361,7 +1361,7 @@ def removeOldAnnotations(self, remove=False, minAgeInDays=30, keepInactiveVersio keep -= 1 report['recentVersions'] += 1 continue - if max(record['created'], record['updated']) < age: + if max(record['created'], record['updated']).timestamp() < age.timestamp(): if remove: self.collection.delete_one({'_id': record['_id']}) Annotationelement().removeWithQuery({'_version': record['_version']}) diff --git a/girder_annotation/test_annotation/test_annotations_rest.py b/girder_annotation/test_annotation/test_annotations_rest.py index 7e17a5529..d69c2e63d 100644 --- a/girder_annotation/test_annotation/test_annotations_rest.py +++ b/girder_annotation/test_annotation/test_annotations_rest.py @@ -569,6 +569,13 @@ def testAnnotationHistoryEndpoints(self, server, user, admin): resp = server.request('/annotation/old', method='GET', user=admin) assert utilities.respStatus(resp) == 200 assert resp.json['abandonedVersions'] == 0 + resp = server.request( + '/annotation/old', method='DELETE', user=admin, params={'versions': -1}) + assert utilities.respStatus(resp) == 400 + assert 'keepInactiveVersions' in resp.json['message'] + resp = server.request( + '/annotation/old', method='GET', user=admin, params={'age': 0, 'versions': 0}) + assert utilities.respStatus(resp) == 200 resp = server.request('/annotation/old', method='DELETE', user=admin) assert utilities.respStatus(resp) == 200 assert resp.json['abandonedVersions'] == 0