Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Job __repr__ throws AttributeError when job_func is None #485

Closed
tmkontra opened this issue Sep 16, 2021 · 2 comments
Closed

Job __repr__ throws AttributeError when job_func is None #485

tmkontra opened this issue Sep 16, 2021 · 2 comments

Comments

@tmkontra
Copy link

>>> 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
Copy link

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
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants