Skip to content

fix: guard against self.unit being None in Job.__repr__#655

Open
juliosuas wants to merge 1 commit intodbader:masterfrom
juliosuas:fix/guard-unit-none-in-repr
Open

fix: guard against self.unit being None in Job.__repr__#655
juliosuas wants to merge 1 commit intodbader:masterfrom
juliosuas:fix/guard-unit-none-in-repr

Conversation

@juliosuas
Copy link
Copy Markdown

@juliosuas juliosuas commented Mar 30, 2026

hit this on jobs that hadn't had a unit set yet:

TypeError: 'NoneType' object is not subscriptable

self.unit is initialized to None (there's even an Optional[str] type hint on it) but __repr__ slices it unconditionally:

self.unit[:-1] if self.interval == 1 else self.unit

so the moment you try to repr a freshly-constructed Job before the unit is set, it blows up. guarded both branches of the ternary with a None check and used "[unit not set]" as placeholder text.

fixes #646.

When Job.interval == 1 and self.unit is None (the initial state),
__repr__ attempted self.unit[:-1] which raised:
  TypeError: 'NoneType' object is not subscriptable

Guard both format paths in __repr__ against self.unit being None by
substituting '[unit not set]' as a safe placeholder.

Fixes dbader#646
@juliosuas
Copy link
Copy Markdown
Author

Quick note: the fix also handles the else-branch in __repr__ where the same self.unit[:-1] pattern appeared in the format string dict. Both paths now safely fall back to '[unit not set]' when self.unit is None. Normal jobs that have been assigned a unit are completely unaffected.

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 this pull request may close these issues.

[CRASH CONDITION] - Guard self.unit against None

1 participant