Skip to content

Commit 25d022e

Browse files
Copilotponyisi
andcommitted
Use timezone-aware datetime for dataset lifecycle ops
Co-authored-by: ponyisi <[email protected]>
1 parent 4d609d9 commit 25d022e

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

servicex_app/servicex_app/resources/internal/dataset_lifecycle_ops.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
2626
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2727
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28-
from datetime import datetime, timedelta
28+
from datetime import datetime, timedelta, timezone
2929

3030
from flask import request, current_app
3131

@@ -39,7 +39,7 @@ def post(self):
3939
"""
4040
Obsolete cached datasets older than N hours
4141
"""
42-
now = datetime.now()
42+
now = datetime.now(timezone.utc)
4343
try:
4444
age = float(request.get_json().get("age", 24))
4545
except Exception:

servicex_app/servicex_app_test/resources/internal/test_dataset_lifecycle_ops.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
2626
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2727
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28-
from datetime import datetime
28+
from datetime import datetime, timezone
2929
from unittest.mock import patch
3030

3131
from pytest import fixture
@@ -43,8 +43,8 @@ def fake_dataset_list(self):
4343
) as dsfunc:
4444
dsfunc.return_value = [
4545
Dataset(
46-
last_used=datetime(2022, 1, 1),
47-
last_updated=datetime(2022, 1, 1),
46+
last_used=datetime(2022, 1, 1, tzinfo=timezone.utc),
47+
last_updated=datetime(2022, 1, 1, tzinfo=timezone.utc),
4848
id=1,
4949
name="not-orphaned",
5050
events=100,
@@ -54,8 +54,8 @@ def fake_dataset_list(self):
5454
did_finder="rucio",
5555
),
5656
Dataset(
57-
last_used=datetime.now(),
58-
last_updated=datetime.now(),
57+
last_used=datetime.now(timezone.utc),
58+
last_updated=datetime.now(timezone.utc),
5959
id=2,
6060
name="orphaned",
6161
events=100,

0 commit comments

Comments
 (0)