← Course Home
Module 13 · Tier 6

Inherit-and-Fix

The most common real-world script task: someone left, you inherited their script, and it's subtly wrong. Ten labs on Module 8 — diagnosing and fixing four real bug categories in a version of Tier 5's own script.

Lab 1

Bug 1: The Missing Return

You're handed filter_flagged_broken(users) — it builds a flagged list correctly but never returns it. Call len(filter_flagged_broken(USERS)). Predict, then run.

CrashesTypeError: object of type 'NoneType' has no len()
Lab 2

Bug 2: The Accumulator KeyError

You're handed count_by_status_broken(users) — it uses counts[u["status"]] += 1 instead of a guarded pattern. Call it on USERS. Predict, then run.

CrashesKeyError on the first status it sees
Lab 3

Bug 3: The Silent Wrong Answer

You're handed is_flagged_broken(user) — it checks is_suspended(user) and has_zero_groups(user) instead of or. Build the flagged-names list with it over USERS. Predict, then run.

[] — no crash, just silently wrong. The real answer has 5 flagged accounts; and instead of or means almost nothing ever matches both conditions at once.
Lab 4

Bug 4: The Direct-Key Crash

You're handed build_report_line_broken(user) — it accesses user["profile"]["department"] directly instead of guarding it. Loop all USERS calling it. Predict how many lines print before it crashes, then run.

→ 7 lines print, then crashesKeyError: 'department' on Layla
Lab 5

Fix 1: Add the Return

Fix filter_flagged_broken by adding the missing return flagged. Confirm len() of the result now.

5
Lab 6

Fix 2: Guard the Accumulator

Fix count_by_status_broken to use counts[status] = counts.get(status, 0) + 1. Call it on USERS.

{'ACTIVE': 8, 'SUSPENDED': 2, 'DEPROVISIONED': 2}
Lab 7

Fix 3: Correct the Logic

Fix is_flagged_broken by changing and to or. Rebuild the flagged-names list.

['Bina', 'Dana', 'Tri', 'Rosa', 'Pat']
Lab 8

Fix 4: Guard the Key Access

Fix build_report_line_broken by using .get("department", "Unknown"). Call it on USERS[7] (Layla) — confirm no crash.

Layla Haddad -- ACTIVE -- Unknown
Lab 9

Which Bug Would You Catch First?

Of the four bugs, three crash loudly (1, 2, 4) and one fails silently (3). Print one sentence: why is bug 3 the most dangerous of the four, even though it's the only one that never crashes?

A crash gets noticed and fixed immediately. A silent wrong answer ships — nobody knows to look until the bad data causes a real problem downstream.
Lab 10 · Capstone

The Fully Hardened Script

Combine all four fixes into one clean script: fetch_users()filter_flagged() (fixed) → print_report() using build_report_line() (fixed) — the same shape as Tier 5's capstone, now defensively written from the start. Run it.


Flagged accounts: 5
Bina Patel -- SUSPENDED -- Sales
Dana Morris -- ACTIVE -- IT
Tri Nguyen -- DEPROVISIONED -- Sales
Rosa Gomez -- SUSPENDED -- IT
Pat Hogan -- DEPROVISIONED -- Sales
Now go practice

Open problems/tier06_inherit_and_fix.py and do all 10 problems locally. Uses fixture.py -- type it in first from DAY1_01_FIXTURE.md if it's not already in this folder. Run python check.py in problems/ to grade everything.

Tier 6 complete

On to Tier 7

the missing-return crash → the accumulator KeyError → the silent wrong answer → the direct-key crash → fixing each one in turn → naming why silent bugs are the most dangerous → the fully hardened script.

← Back to Module 13