Repository navigation
Fix Job.__repr__ crash on a partially-composed default-interval job - #662
Closed
afonsojanu wants to merge 1 commit into
Closed
afonsojanu wants to merge 1 commit into
afonsojanu wants to merge 1 commit into
Conversation
repr() slices self.unit to drop the trailing 's' for singular units, but a freshly created Job (e.g. schedule.every(), interval defaults to 1) has unit=None until a time-unit property or do() sets it, so that slice raised "TypeError: 'NoneType' object is not subscriptable". There was already a test guarding the interval>1 case for exactly this partially-composed state, it just never exercised interval==1. Route both repr branches through a small helper that leaves None untouched, and add a case for the default interval to the existing test.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the crash reported in #646.
Job.__repr__tries to drop the trailingsfrom the unit name for singular jobs (self.unit[:-1] if self.interval == 1 else self.unit), but aJobdoesn't get aunituntil one of the time-unit properties (.minute,.day, ...) or.do()sets it. Sinceevery()defaultsintervalto 1,repr(schedule.every())slicesNoneand blows up withTypeError: 'NoneType' object is not subscriptable. This can bite you in an interactive session or any debug logging that reprs a job before it's fully composed.There's actually already a test for exactly this "partially-composed job" scenario (
test_to_repr'sschedule.every(10)case), but it only happens to dodge the bug becauseinterval=10takes the other branch of that conditional and never slices anything.Fix: route both places that do this slicing through a small
format_unithelper that passesNonestraight through, and add a case to that same test for the default interval of 1, which is the one that actually crashed.now returns
'Every 1 None do [None] (last run: [never], next run: [never])'instead, matching what the interval>1 case already does.