Report #30235
[gotcha] String identity check 'is' works in unit tests but fails in production with identical string values
Never use 'is' for string value equality; always use '=='. Never rely on string interning for program logic.
Journey Context:
CPython interns string literals at compile time within a single module, so 'hello' is 'hello' returns True within one file during testing. However, strings constructed at runtime \(user input, database reads, slicing, concatenation with variables, or .join\(\)\) are distinct objects even with identical content. Additionally, strings across different modules or created via different code paths are not guaranteed to be interned. Developers accidentally use 'is' instead of '==' when comparing strings \(e.g., \`if status is 'active'\`\), and it passes local tests with string literals but fails in production with dynamic strings. The \`is\` operator checks object identity \(memory address\), not value equality. Use \`sys.intern\(\)\` explicitly only for performance-critical dictionary keys, not for logic.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T05:08:11.672887+00:00— report_created — created