CI tests three Pythons; production runs a fourth

Take a census of the Pythons in one small web project, on the day this got fixed:

interpreter where it lives ran the tests? runs the site?
3.11 CI matrix yes no
3.12 CI matrix yes no
3.13 CI matrix yes no
3.12 the server's venv no yes
3.12.4 the dev machine's venv no no

Every push ran the test suite on three interpreters. The one carrying production traffic was tested by none of them, and neither was the one the developer actually works in. Five Pythons, three green checkmarks, and the only row that matters got there by coincidence.

The coincidence is the problem

To be precise about the failure: CI didn't test the wrong version. Production's 3.12 sat inside the matrix, so the right version was covered. The problem is that nothing connected those two facts.

The server runs whatever python3 the distro ships. That's chosen by apt on the box, and nobody ever asks the repo. The matrix is a list of guesses, one of which happens to be true. The day the server takes an LTS upgrade, the guesses stay exactly as green as they were, and the truth moves underneath them, because CI can't see the server at all. There's no link to break. That's why it breaks silently.

The matrix is the honest default, for libraries

The matrix didn't get into the workflow by carelessness. It's the community default, copied from project to project, and for the projects it was designed for, it's correct. A library can't know where its users will run it. The matrix is its deployment model, and testing 3.11 through 3.13 is how it keeps a promise it made to strangers.

An app is the opposite case and gets the same default anyway. An app knows exactly where it runs: one server, one venv, one interpreter. Its CI exists to predict that machine.

Testing two machines that will never exist is coverage theater, and it isn't even free. It triples the CI minutes. It trains you to chase deprecation warnings for interpreters you'll never deploy. Worst of all, it feels like thoroughness while leaving the actual deployment untested. The checkmarks in the table above are what that feels like in practice.

The drift nobody can see

The way the app is deployed makes the blind spot worse. The install script builds the venv from the distro's python3 exactly once. Every later deploy reuses that venv. The deploy script only runs pip when requirements.txt has changed: a redundant pip run costs seconds, and skipping one that was needed costs more.

Now let the distro upgrade its python3. Nothing rebuilds: same venv, same service, old interpreter, and no error anywhere to say so. CI's matrix doesn't notice, because it was never watching the server. The deploys don't notice, because they only compare file lists. The site keeps serving from an interpreter that's quietly no longer the one anyone tested, or meant to test.

Every layer is doing exactly what it was written to do, and the answer to "which Python is production?" drifts away from every answer the repo gives.

One file, three readers

The fix is to stop asking anyone to remember the version and write it down once, at the repo root, in a .python-version file:

3.12

Three things read it:

  • CI installs it. GitHub's setup-python action takes python-version-file: .python-version. The matrix is gone, and the workflow has no version of its own to drift from.
  • The deploy script enforces it. After pulling and before restarting, it compares the venv's interpreter against the file. A mismatch fails the deploy loudly, prints the commands to rebuild, and leaves the current service running. That's the safe way to fail: the site keeps serving on the old interpreter while a human decides, instead of restarting into a half-migrated venv.
  • The deployment docs explain it, along with the drift described above, so the next person who upgrades the server meets the contract before it bites.

Changing the version on purpose is now one commit: the file, plus whatever needs to change with it. CI follows, the deploy follows, and the table at the top of this note collapses to two rows that agree.

What a pin can't do

Honesty requires one more paragraph. A file in the repo is a claim, not a guarantee. The server still picks its own python3, and the deploy check fires after the drift exists rather than preventing it.

The strong version of this fix is provisioning the interpreter from the repo, the way some stacks vendor their runtimes. That would make drift impossible instead of visible, and it's more machinery than one server on one distro has earned. The failure that used to be invisible is now loud, cheap, and carries its own repair instructions. For a web app, that's the whole difference between a version matrix and a version contract.

Keep the matrix for libraries. For an app, test the Python you ship, and make the repo, not apt, the place the version is decided.