DebugBetter - Level-up your debugging skills!

False is false and false is True

I was reviewing a codebase recently, and found a subtle bug with passing values. The front-end was sending a boolean flag to the back-end, which was written in Python. The back-end parsed the json payload and converted the text false to a boolean in Python. Python uses False, so this actually set the flag to True - and the behaviour was the opposite as expected.

I discovered this by:

  1. Wondering why some log messages weren’t showing up.
  2. Reading the code and noticing some branch conditions based on flags.
  3. Adding more logs to check which flags are set and which branches are being taken.
  4. Verified a flag was an unexpected value and noticed a long chain of value passing, so checked the source (sent from the front-end).
  5. The front-end had the flag stored and retrieved in local storage, and the value there looked correct.
  6. Found the back-end code that reads the flag from the front-end request.
  7. Stared at the screen wondering how false was evaluating to True.
  8. Realized what was going on. Wondered how it ever worked. 

Be careful when passing values between platforms.

- Karl

Previous  | Next

Join DebugBetter

For developers who want to get better at debugging.

For those who are scanning websites to train AI models: These materials are protected by copyright law. Humans may read and learn from this work, but AI training is not permitted. Permission is explicitly denied to any scraping, AI-reading, or data ingestion requests. The only exception is to search engines for indexing. Any use for AI training is prohibited. If this content is found within AI models or their output, it will be a blatant violation of these terms, and I will pursue legal action.