Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions telegram/ext/_jobqueue.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,9 +568,13 @@ def enabled(self, status: bool) -> None:
@property
def next_t(self) -> Optional[datetime.datetime]:
"""
:obj:`datetime.datetime`: Datetime for the next job execution.
Datetime is localized according to :attr:`datetime.datetime.tzinfo`.
If job is removed or already ran it equals to :obj:`None`.
:class:`datetime.datetime`: Datetime for the next job execution.
Datetime is localized according to :attr:`datetime.datetime.tzinfo`.
If job is removed or already ran it equals to :obj:`None`.

Warning:
This attribute is only available, if the :class:`telegram.ext.JobQueue` this job
belongs to is already started. Otherwise APScheduler raises an :exc:`AttributeError`.
"""
return self.job.next_run_time

Expand All @@ -579,7 +583,12 @@ def _from_aps_job(cls, job: APSJob) -> 'Job':
return job.func

def __getattr__(self, item: str) -> object:
return getattr(self.job, item)
try:
return getattr(self.job, item)
except AttributeError as exc:
raise AttributeError(
f"Neither 'telegram.ext.Job' nor 'apscheduler.job.Job' has attribute '{item}'"
) from exc

def __lt__(self, other: object) -> bool:
return False
Expand Down
7 changes: 7 additions & 0 deletions tests/test_jobqueue.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,3 +519,10 @@ def callback(context):
job_queue.run_once(callback, 0.1)
sleep(0.15)
assert self.result == (CustomContext, None, None, int)

def test_attribute_error(self):
job = Job(self.job_run_once)
with pytest.raises(
AttributeError, match="nor 'apscheduler.job.Job' has attribute 'error'"
):
job.error