F06 · PREDICT · DEBUG · VERIFY LOCALLY
F06 Regression Debugging: Why Did Filtering Break Existing Work?
A category filter removes other records from the source collection instead of merely showing matches. A later add and save persists the loss.
Back to the practice route →The bug and the local contract
def filter_documents(documents, category):
documents[:] = [item for item in documents
if item["category"] == category]
return documents
- Write a failing test before inspecting filter_documents with a breakpoint or log. Return matches in order without mutating the source. Apply the same contract to the tag-filter variant.
- Test hits, misses, empty input and different categories. Filtering then adding, saving and reloading must retain every record. Run F01–F05 regressions, not just new tests.
- Deliver a before/after diff, a local Git commit, your own counterexample and a runnable README for someone else. The page does not perform real saves or Git operations.
Use fictional document metadata. The web model does not execute arbitrary code.
01 · CONTROLLED MODEL
Predict, then inspect each step
This models only the selected preset. It does not execute your Python draft or read/write computer files. One matching case does not establish correctness for all inputs.
Checks output content, order, unchanged source and later operations. Only the result list is separate; record deep copies are not implied. Save/reload is a JSON state model only.
Unchecked or invalidated
Before
{
"records": [
{
"id": "doc_00000000000000000000000000000001",
"title": "A",
"category": "course",
"tags": [
"study",
"study"
]
},
{
"id": "doc_00000000000000000000000000000002",
"title": "B",
"category": "club",
"tags": [
"club"
]
},
{
"id": "doc_00000000000000000000000000000003",
"title": "C",
"category": "course",
"tags": [
"study"
]
}
],
"query": "course"
}Model result
Step through the trace to reveal the result
Progressive learning hints
Hints are fixed teaching content. Their use is recorded.
Hint 1
Capture source IDs before filtering. When the result looks right, is the source still complete?
Hint 2
Inspect the assignment target: documents[:] = ... mutates the caller’s list. Separate selecting results from changing the library.
Hint 3
Build a new ordered result list, then regress through add, save and reload instead of asserting only the filter output.
My Python draft
Save and export your draft here. Code is not executed or synced to the starter. Draft, input or strategy edits invalidate earlier model results and self-reports.
Local learning records
Saved only in this browser; export is available. No cross-device sync or proof of mastery. Earlier F01 and six-task records are preserved through migration.
- F06 opened: —
- Model check: Unchecked or invalidated
- Local tests (self-reported): —
- Highest hint level: 0/3
- Reference viewed: —
- Unaided variant (self-reported): —
02 · Repair your local project
Start any task independently: its package contains that task’s bug and a runnable baseline for the other business functions. Python 3.11+, standard library only. See the package’s verification notes for tested environments.
- Extract into a new directory. Open a terminal and identify the file being run. Run public tests to reproduce the bug; consult the package’s intentional-failure list.
- Write a hypothesis and choose a value to inspect. Repair the specified function, retain public tests and record the diff and a minimal counterexample.
- Run this task’s tests, then the full regression suite. Web-model results do not replace local execution; self-reports are not remotely verified by this site.
python check_environment.py python -m unittest tests.test_f06 -v python -m unittest discover -s tests -v
Inspect git diff, add a failing category-filter test, set a breakpoint where the collection shrinks, then run F01–F05 regression. Commit your own changes; preserve others’ work.
03 · Independent variant
Independently implement filter_by_tag(documents, tag) in challenges.py without steps. Test matches, misses, empty input and duplicate tags: each matching record appears once in order, with unchanged input. Supply your own counterexample and repair explanation.
python -m unittest tests.test_variants -v
Implement from the requirement, replace the skipped placeholder in tests/test_student_counterexamples.py and add an assertion that exposes the original bug. Explain the failure. Hint or reference use excludes an unaided completion record for this attempt.
Reference explanation and answer
Try your own repair first. Opening or downloading the reference records answer use. Passing reference tests establishes only that the materials run.
View reference explanation (records answer use)
Destructive filtering replaces the library instead of selecting results. Pure filtering creates a result list, not necessarily deep-copied records; independent editing still follows F02. Saving persists the existing state and cannot repair earlier loss.
Download this task’s reference (answer) · Version and source digest
Course references and review
- VSCode: day 9 debugging
Break before and after filtering; compare the source and return value.
- VSCode: day 7 Git
Inspect your repair diff without reverting others’ work.
- Git: m2 local commits
Retain before/after test results and your local commit.
- Git: m3 comparing diffs
Compare the working tree, staging area and repository in the visible section.
- Git: m6 undo and recovery
Undo only your own exercise changes and explain the affected scope first.