Fix replace() to register unregistered functions#207
Conversation
When calling `docket.replace()` with an unregistered function, the method wasn't registering it with the docket. This caused tasks to be scheduled successfully but fail during execution when the worker couldn't find the function in the task registry. The issue existed because `replace()` was missing the `else: self.register(function)` clause that `add()` has. This meant that while the Lua scheduling script correctly scheduled the task (acting like an add when the key doesn't exist), the Python function object wasn't available for the worker to execute. Added the missing registration logic to match `add()`'s behavior, making `replace()` truly idempotent and safe to call regardless of whether a task with that key already exists. Also added a test to verify that `replace()` on a non-existent key schedules and executes the task correctly. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
|
Claude finished @chrisguidry's task —— View job Code Review for PR #207: Fix replace() to register unregistered functionsThank you for this fix! I've reviewed the changes and here's my feedback: ✅ Review SummaryThe PR correctly addresses the issue where Review Checklist
Code Quality & Best Practices ✅The implementation is clean and follows the existing patterns: src/docket/docket.py:444-445 else:
self.register(function)This exactly mirrors the logic in the Test Coverage ✅The new test
Potential Issues & Edge Cases ✅None identified. The change handles all scenarios correctly:
Performance Considerations ✅No performance impact:
Security Considerations ✅No security concerns:
Documentation Consideration 📝Minor suggestion: The docstring for ConclusionLGTM! 👍 This is a well-crafted fix that correctly addresses the issue. The code is clean, the test coverage is appropriate, and the change makes the API more consistent and predictable. The fix ensures Great work on identifying and fixing this subtle but important bug! |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #207 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 48 48
Lines 7505 7513 +8
Branches 395 395
=========================================
+ Hits 7505 7513 +8
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
📚 Documentation has been built for this PR! You can download the documentation directly here: |
When calling
docket.replace()with an unregistered function, the method wasn't registering it with the docket. This caused tasks to be scheduled successfully but fail during execution when the worker couldn't find the function in the task registry.The Issue
The
replace()method was missing theelse: self.register(function)clause thatadd()has. This meant that while the Lua scheduling script correctly scheduled the task (acting like an add when the key doesn't exist), the Python function object wasn't available for the worker to execute.This became apparent when testing whether
replace()on a non-existent key acts as a no-op, an error, or like anadd(). The Lua script showed it should act likeadd(), but the missing registration caused execution failures.The Fix
Added the missing registration logic to
replace()(lines 444-445 insrc/docket/docket.py) to matchadd()'s behavior:This makes
replace()truly idempotent and safe to call regardless of whether a task with that key already exists.Testing
test_replace_without_existing_task_acts_like_add()to verify thatreplace()on a non-existent key schedules and executes correctly🤖 Generated with Claude Code