Fix KeyError: 'Slot' when running breadth command#40
Open
1234-ad wants to merge 1 commit intometakgp:mainfrom
Open
Fix KeyError: 'Slot' when running breadth command#401234-ad wants to merge 1 commit intometakgp:mainfrom
1234-ad wants to merge 1 commit intometakgp:mainfrom
Conversation
- Add proper bounds checking before accessing cells array - Filter out None values from unavailable_slots list using dropna() - Add None check in find_all_unavailable_slots to skip empty strings - Add check for parentTable existence before processing - Add safety check for overlaps dictionary key access - Strip text values to avoid empty string issues - Add warning message when course table is not found - Ensure all_unavailable_slots is not empty before filtering Fixes metakgp#34
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.
Description
This PR fixes the
KeyError: 'Slot'error that occurs when running the breadth command, addressing issue #34.Problem Statement
When running:
The script crashes with a
KeyError: 'Slot'error. This happens because:cells[5]without checking if the array has enough elementsunavailable_slotslist cause issues in downstream processingfind_all_unavailable_slotsfunction doesn't handle None/empty values properlyRoot Causes Identified
1. Unsafe Array Access (Line 322-326)
2. None Values in unavailable_slots (Line 333)
3. No None Handling in find_all_unavailable_slots
The function didn't filter out None/empty values before processing.
4. Missing Table Existence Check
No check if
parentTableexists before callingfind_all.Changes Made
1. Added Proper Bounds Checking
2. Filter None Values from unavailable_slots
3. Enhanced find_all_unavailable_slots
4. Added Table Existence Check
5. Safe Filtering with Empty Check
Benefits
✅ Crash Prevention: No more KeyError when cells array is shorter than expected
✅ None Handling: Properly filters out None values throughout the pipeline
✅ Graceful Degradation: Continues execution even if course table is missing
✅ Data Integrity: Strips whitespace and validates data before processing
✅ Better Error Messages: Warns users when tables are not found
✅ Robust Filtering: Handles edge cases in slot filtering logic
Testing Checklist
.dropna()Technical Details
Error Flow (Before):
cells[5]→ IndexError caught, set to NoneSlot: Noneto listfind_all_unavailable_slots(unavailable_slots)→ Tries to iterate NoneFixed Flow (After):
len(cells) > 5first.dropna()to filter Nonefind_all_unavailable_slots(unavailable_slots)→ Filter empty values firstExample Output
Before (crashes):
After (works):
Or if table is missing:
Related Issue
Closes #34
Additional Notes