6.2 · Recurring issues (playbook)

Level 6 · In practice

6.2Recurring issues (playbook)

Goal: have a “symptom → causes → actions” playbook for common Python blockers.
Estimated time: 12 min · If you only have 5 min: read “The essentials in 30s” + the diagram.

The essentials in 30 seconds

  • Reflex: one symptom = likely causes = one targeted action — diagnose before touching the code.
  • Read: the traceback reads bottom-up: the last line names, the top locates.
  • Isolate: any gap between local and CI is fixed with venv, pinned requirements and aligned versions.

Nabil thread — the playbook taped next to the screen

Nabil keeps this playbook next to his screen. Verdict after one year: three lines served him most — the non-activated venv behind ModuleNotFoundError, mixed tabs + spaces, and red CI while everything was green locally. For each, he ended up applying the sequence (read the traceback, check the cause, fix) instead of editing at random.

Observed symptom, verified causes, actions in order: the reflex holds in three steps.

Diagnose before rerunning

Most Python blockers are classics: each symptom has typical causes and one targeted action. The table below groups the most frequent situations, from import to deployment.

SymptomLikely causesActions
ModuleNotFoundErrorwrong interpreter, venv not activated, file in the wrong placeselect the right interpreter, activate the venv, check the path
IndentationError / TabErrormixed tabs + spacesconvert to 4 spaces, black to normalise
NameErrortypo, variable out of scope, forgotten importreread the last line, check scope and imports
KeyError on dictmissing key, direct access.get() with a default + validate input data
It worked yesterday (dependencies)mixed global, drifted versionsvenv + pinned requirements, rebuild to prove
Red tests after refactorbehaviour changed unintentionallyread THE failing test, fix the code (not the test), rerun
Unreachable API in containerlocalhost host instead of 0.0.0.0CMD with --host 0.0.0.0, -p to publish
Red CI, green localdifferent versions, missing test, absent secretalign versions (requirements), reproduce locally, check secrets
Slow script on large volumesPython loops instead of vectorised/generatorprofile, vectorise (pandas/NumPy) or yield
Common misinterpretation: “the playbook replaces diagnosis”. No. The table gives likely causes, not a verdict: read the traceback (last line + file), verify, then apply the targeted action.
Text version of the diagram (SEO / screen readers / translation): Playbook method: 1) Name the observed symptom (ModuleNotFoundError, IndentationError, NameError, KeyError, dependencies, red tests, container, CI, slowness). 2) Hold the table's likely causes without concluding alone. 3) Apply the actions in order (venv, 4 spaces, scope, .get, rebuild, failing test, 0.0.0.0, versions, vectorise). 4) Read the traceback bottom-up and lock in (venv, hints, tests). Lesson: a recurring hassle calls for a method, not random edits.

Ready-to-say script — diagnosing without random edits (30 s)

“My symptom: [ModuleNotFoundError / KeyError / red CI / slowness]. I read the traceback bottom-up, identify the playbook's likely cause, apply the targeted action and verify.”

Copy-paste template — safe access + precise error

def taux_ville(ligne: dict) -> float:
    ville = ligne.get("ville", "inconnue")
    if ville == "inconnue":
        raise ValueError("clé 'ville' absente de la ligne")
    return float(ligne.get("taux", 0.0))

VSE / small budget

No formal table: one symptom, the playbook's likely cause, the action and the noted owner.

SME Algiers

Fold local realities into diagnosis: installed versions, shared workstations, known Monday peaks.

Remote / hybrid

Add immediate written logs to the actions: at a distance, an unrecorded symptom looks like a working system.

Intercultural

Spell out findings in writing: what seems obvious (which venv, which version) is not obvious to everyone.

Caution: General reminder: if a secret is exposed or red CI relates to secrets, regenerate the key, move it to an environment variable outside the repo and have the designated contact validate; this guide gives no legal advice.

48h challenge — apply tomorrow

Spot 1 current symptom (import, KeyError, red CI), apply the playbook line (traceback read + cause verified + targeted action).

Section exit checklist
  • I can link a symptom to its likely causes.
  • I read the traceback bottom-up before fixing.
  • I can lock in with venv, hints and tests.
Self-assessment 1-5: diagnosis before editing?traceback read carefully?
Check your understanding

Nabil's script raises KeyError on a sales dict. Which reflex does the playbook apply?

💡

The same hassle returning endlessly is not ten incidents: it is a method to fix (venv, tests, hints).