dbader / schedule

Python job scheduling for humans.
https://schedule.readthedocs.io/
MIT License
11.73k stars 959 forks source link

Job __repr__ throws AttributeError when job_func is None #485

Closed tmkontra closed 1 year ago

tmkontra commented 3 years ago
>>> s._job
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/path/to/my/virtualenv/site-packages/schedule/__init__.py", line 284, in __repr__
    args = [repr(x) if is_repr(x) else str(x) for x in self.job_func.args]
AttributeError: 'NoneType' object has no attribute 'args'

Line 284 (and similarly line 285 for kwargs) assumes self.job_func is not None (and has the "args" attribute). I think it needs to use logic similar to line 264 (and line 265, respectively for kwargs).

It may be helpful to extract line 264 to a reusable property:

@property
def _job_func_args(self):
    return () if self.job_func is None else self.job_func.args

I can draft a PR if that would be helpful.

For context, I am using schedule as a schedule-builder interface, (i.e. just Job definitions without do).

jmcvetta commented 1 year ago

I've opened a PR with an alternative implementation of a fix. My approach is to fall back to the simpler .__str__() representation of the Job when it does not have the attributes needed to construct a pretty .__repr__() representation.

https://github.com/dbader/schedule/pull/573/files

SijmenHuizenga commented 1 year ago

Thanks for reporting and debugging! This has been resolved in #569 and will be part of the next release.