Skip to content

Commit cef0d21

Browse files
committed
Fix conversion of datetimes in TransferData
The `deadline` field accepts a datetime but does not stringify it. On `DeleteData`, the same field exists, with the same semantics, and is passed to our internal `stringify()` helper. Apply the same here as the fix so that the two remain consistent. A new unit test verifies the results. Note that this calls `str(deadline)`, which *does not* produce an ISO 8601 date string. This was the behavior in the 3.x versions of the SDK as well, which is part of why it is being kept rather than fixed at this time. Fixing it will require evaluating what the Transfer APIs accept. Fixes #1371
1 parent 5df4a27 commit cef0d21

3 files changed

Lines changed: 24 additions & 1 deletion

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Fixed
2+
-----
3+
4+
- Fixed a bug in ``globus_sdk.TransferData`` which failed to convert
5+
``deadline`` to a string when a ``datetime.datetime`` object is given.
6+
(:pr:`NUMBER`)

src/globus_sdk/services/transfer/data/transfer_data.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import typing as t
66
import uuid
77

8+
from globus_sdk._internal.remarshal import stringify
89
from globus_sdk._missing import MISSING, MissingType
910
from globus_sdk._payload import GlobusPayload
1011

@@ -176,7 +177,7 @@ def __init__(
176177
self["destination_endpoint"] = destination_endpoint
177178
self["label"] = label
178179
self["submission_id"] = submission_id
179-
self["deadline"] = deadline
180+
self["deadline"] = stringify(deadline)
180181
self["source_local_user"] = source_local_user
181182
self["destination_local_user"] = destination_local_user
182183
self["verify_checksum"] = verify_checksum

tests/unit/helpers/test_transfer.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import datetime
2+
13
import pytest
24

35
from globus_sdk import MISSING, DeleteData, TransferData
@@ -298,3 +300,17 @@ def test_add_filter_rule():
298300
)
299301
def test_ls_format_filter(filter, expected):
300302
assert _format_filter(filter) == expected
303+
304+
305+
@pytest.mark.parametrize(
306+
"deadline_str",
307+
[
308+
pytest.param("2026-02-27 09:36:50.517299", id="naive_w_microseconds"),
309+
pytest.param("2020-01-01 08:22:12+04:00", id="plus4"),
310+
],
311+
)
312+
def test_transfer_data_stringifies_deadline(deadline_str):
313+
deadline_dt = datetime.datetime.fromisoformat(deadline_str)
314+
315+
tdata = TransferData(GO_EP1_ID, GO_EP2_ID, deadline=deadline_dt)
316+
assert tdata["deadline"] == deadline_str

0 commit comments

Comments
 (0)