﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
36633	TaskBackend run_after validation assumes datetime when USE_TZ=True	Chris M		"I’ve been working on an implementation of a TaskBackend using Google Cloud Tasks. I ran across a bit of confusion regarding the {{{run_after}}} parameter validation.

The DEP originally referenced that the value could be a datetime or a timedelta. The released implementation looks like it only documents it as a datetime, so I’m not sure if it was meant to support timedelta. However, I tried using a timedelta with the {{{USE_TZ=True}}} and the validation in BaseTaskBackend assumes that the run_after value is a {{{datetime}}} and I got an error 

Calling code: {{{my_task.using(run_after=timedelta(seconds=10)).enqueue()}}}

Error: {{{AttributeError: 'datetime.timedelta' object has no attribute 'utcoffset'}}}

If I run the code using a {{{timedelta}}} and with {{{USE_TZ=False}}} then the error isn't thrown and my backend can process it.

The code throwing the error in the {{{BaseTaskBackend}}} is

{{{#!python
        if (
            settings.USE_TZ
            and task.run_after is not None
            and not timezone.is_aware(task.run_after)
        ):
            raise InvalidTask(""run_after must be an aware datetime."")
}}}

I think it would be best for this condition to verify that the provided {{{run_after}}} is a {{{datetime}}} before calling {{{timezone.is_aware}}}. I'm hoping for some confirmation if this is the right way to proceed.

I think it would be great to support {{{timedelta}}} directly as well by updating the type annotations on {{{Task}}}, but I couldn't determine through the PR history if this was removed during implementation.
"	Bug	closed	Tasks	6.0	Release blocker	wontfix		Jake Howard	Unreviewed	0	0	0	0	0	0
