agronholm / apscheduler

Task scheduling library for Python
MIT License
6.11k stars 698 forks source link

fix: Set CRON trigger fields #938

Closed WillDaSilva closed 1 month ago

WillDaSilva commented 1 month ago

Changes

Fixes #923

Checklist

If this is a user-facing code change, like a bugfix or a new feature, please ensure that you've fulfilled the following conditions (where applicable):

If this is a trivial change, like a typo fix or a code reformatting, then you can ignore these instructions.

Updating the changelog

If there are no entries after the last release, use **UNRELEASED** as the version. If, say, your patch fixes issue #999, the entry should look like this:

* Fix big bad boo-boo in the async scheduler (#999 <https://github.com/agronholm/apscheduler/issues/999>_; PR by @yourgithubaccount)

If there's no issue linked, just link to your pull request instead by updating the changelog after you've created the PR.

agronholm commented 1 month ago

The proper fix would be to override __init__() to accept the individual fields, and call __attrs_init__() to fill in the fields we want to keep, and then fill in the _fields attribute. A test that fails without the fix would also be required.

WillDaSilva commented 1 month ago

A test that fails without the fix would also be required.

Yup. I plan to add one before I mark this as ready for review.

fill in the fields we want to keep

@agronholm I'm not sure what you mean by this. Don't we want to keep all of the fields? Specifically, that is:

If you feel you know how to fix it, and that fixing it yourself would be easier than helping me fix it, feel free to take it away. Otherwise I'm happy to see this through. Whatever's easiest for you.

agronholm commented 1 month ago

The initializer parameters from year to second were only supposed to be used to fill out the appropriate fields, and should not be stored in the instance. That this happened was an artifact of the class being transformed into an attrs class. Before I started using attrs in APScheduler, I had intended these to be InitVars when the trigger class was going to be a data class, but attrs does not have such a feature. Instead, its docs recommend overriding __init__(). I'll see about doing this tomorrow.

agronholm commented 1 month ago

Closing in favor of commit 0240dce0.