From e1558f4e23d657e71685e7b1a9e14b277c1e3d36 Mon Sep 17 00:00:00 2001 From: Arpit Jain Date: Mon, 29 Jun 2026 11:35:26 +0900 Subject: [PATCH 1/2] Validate that start date precedes end date The CLI validator parsed --start-date and --end-date for ISO format but never checked their order, so an inverted range was sent to CMR and the user only saw an opaque HTTP 400 at request time. Raise a clear error when start is later than end. Equal dates stay allowed. Fixes #145 Signed-off-by: Arpit Jain --- CHANGELOG.md | 4 ++++ subscriber/podaac_access.py | 11 +++++++++-- tests/test_subscriber.py | 7 +++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9dd5b05..30ff501 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) +## [Unreleased] +### Fixed +- Raise a clear error when --start-date is later than --end-date instead of an opaque HTTP 400 from CMR [145](https://github.com/podaac/data-subscriber/issues/145) + ## [1.15.2] ### Fixed - Fixed bug where --subset in combination with the subscriber caused errors diff --git a/subscriber/podaac_access.py b/subscriber/podaac_access.py index a898569..c7f7cde 100644 --- a/subscriber/podaac_access.py +++ b/subscriber/podaac_access.py @@ -192,20 +192,27 @@ def validate(args): raise ValueError('Error parsing "--bounds": S Latitude must be <= N Latitude') + start = None + end = None + if args.startDate: try: - datetime.strptime(args.startDate, '%Y-%m-%dT%H:%M:%SZ') + start = datetime.strptime(args.startDate, '%Y-%m-%dT%H:%M:%SZ') except ValueError: raise ValueError( "Error parsing '--start-date' date: " + args.startDate + ". Format must be like 2021-01-14T00:00:00Z") # noqa E501 if args.endDate: try: - datetime.strptime(args.endDate, '%Y-%m-%dT%H:%M:%SZ') + end = datetime.strptime(args.endDate, '%Y-%m-%dT%H:%M:%SZ') except ValueError: raise ValueError( "Error parsing '--end-date' date: " + args.endDate + ". Format must be like 2021-01-14T00:00:00Z") # noqa E501 + if start is not None and end is not None and start > end: + raise ValueError( + "Start date and end date are out of order. End date needs to be a later time than start date.") # noqa E501 + if 'minutes' in args: if args.minutes: try: diff --git a/tests/test_subscriber.py b/tests/test_subscriber.py index 01e468b..8cd93a6 100644 --- a/tests/test_subscriber.py +++ b/tests/test_subscriber.py @@ -146,6 +146,13 @@ def test_validate(): assert a.endDate == '2021-01-01T00:00:00Z' assert a.provider == "POCLOUD" + # start date equal to end date is allowed + validate(["-c", "dataset", "-d", "/data", "-sd", "2021-01-01T00:00:00Z", "-ed", "2021-01-01T00:00:00Z"]) + + # start date after end date should raise a clear error + with pytest.raises(ValueError): + validate(["-c", "dataset", "-d", "/data", "-sd", "2021-01-01T00:00:00Z", "-ed", "2020-01-01T00:00:00Z"]) + a = validate(["-c", "dataset", "-d", "/data", "-p", "ANEWCLOUD"]) assert a.provider == 'ANEWCLOUD' From 23b48d3a4955d953841d8fb2a6a467957b9b44e1 Mon Sep 17 00:00:00 2001 From: Arpit Jain Date: Tue, 30 Jun 2026 09:55:19 +0900 Subject: [PATCH 2/2] Reword date-range error to allow equal dates per review Signed-off-by: Arpit Jain --- subscriber/podaac_access.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subscriber/podaac_access.py b/subscriber/podaac_access.py index c7f7cde..6e4c226 100644 --- a/subscriber/podaac_access.py +++ b/subscriber/podaac_access.py @@ -211,7 +211,7 @@ def validate(args): if start is not None and end is not None and start > end: raise ValueError( - "Start date and end date are out of order. End date needs to be a later time than start date.") # noqa E501 + "--end-date must be greater than or equal to --start-date.") if 'minutes' in args: if args.minutes: