The Generated Helper Passed Locally, Then Died in a Clean Container Because It Read a Global I Never Passed
I almost shipped a small feature-flag helper that worked on my laptop and crashed in the clean Docker image. The generated source looked self-contained, and my local smoke test gave the exact boolean I expected, so I assumed the problem was the deployment environment. It was not. The generated function was silently reading module-level variables that my interactive shell still had from an older…
The generated helper code worked locally on the reporter's laptop but failed in a clean Docker container because it was reading globally defined variables that were not passed as parameters. The function was expected to check if a feature flag was enabled for a given name, but it relied on three free globals: DEBUG, FEATURE_STORE, and DEFAULT_FEATURES.
The generated function did not specify these globals, and a casual look at the code could overlook this hidden dependency. The reporter's local Python session still had leftover variables from a previous experiment, which prevented the function from failing in the interactive shell. However, when run in an empty namespace that simulated a clean container, the function raised a NameError because the required globals were not defined.
To prevent this issue, the reporter built a tiny harness that checks for free globals before execution. The analyzer scans the generated code to find every name it loads that is neither assigned nor received as a parameter. By identifying these free globals, the reporter could ensure the generated code is self-contained and does not rely on unexpected external state.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.