fix(gateway): wrap cron helpers with staticmethod to prevent self-binding#5299
Merged
fix(gateway): wrap cron helpers with staticmethod to prevent self-binding#5299
Conversation
…ding Plain functions imported as class attributes in APIServerAdapter get auto-bound as methods via Python's descriptor protocol. Every self._cron_*() call injected self as the first positional argument, causing TypeError on all 8 cron API endpoints at runtime. Wrap each import with staticmethod() so self._cron_*() calls dispatch correctly without modifying any call sites. Co-authored-by: teknium <teknium@nousresearch.com>
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.
Summary
Salvage of PR #5167 by @MichaelWDanko with an improved fix approach.
Bug: All 8 cron API endpoints in the API server crash with
TypeErrorat runtime. Plain functions imported as class attributes (from cron.jobs import list_jobs as _cron_list) become bound methods when called viaself._cron_*(), injectingselfas the first positional argument.Original PR's fix: Changed all 8 call sites to
type(self)._cron_*().This PR's fix: Wraps each import with
staticmethod()at the declaration site. This prevents the descriptor binding while keeping all call sites unchanged — cleaner and more idiomatic.Changes
gateway/platforms/api_server.py— 8staticmethod()wrappers added after the cron import blocktests/gateway/test_api_server_jobs.py— 3 regression tests (pause, list, update) verifying noselfinjection with plain-function patches wrapped instaticmethod()Test results
test_api_server_jobs.py: 35 passed (32 existing + 3 new)test_api_server.py+test_api_server_jobs.py: 129 passed, 0 failuresCloses #5167. Contributor authorship preserved.