19 / 20 · Book 15 · Your First SELECT -- Reading the Source of Truth← prev⊞ allnext →Get the book →
1.19Question 2
Prompt: Your team's test suite uses SELECT * throughout all database verification queries. A new migration adds a JSONB column to the users table, and suddenly 40% of your tests fail even though no business logic changed. What happened, and how would you redesign the verification approach?
What a strong answer should cover:
- Understanding that SELECT * returns all columns, so adding a new column changes the result shape
- Positional access (row[0], row[1]) breaks when column order changes
- The fix: use explicit column lists and DictCursor for named access
- Test resilience as a design principle
Example answer:
- The tests break because they use positional indexing (row[0], row[1]) against the results of SELECT *. When the new column is added, the positions shift for any columns that come after it in table order.
- I would refactor every verification query to list columns explicitly:
SELECT id, name, email, role FROM usersinstead ofSELECT *. Then I would switch from positional access to DictCursor so assertions readuser["role"] == "viewer"instead ofrow[3] == "viewer". - Going forward, I would establish a team convention: no SELECT * in test automation, mandatory DictCursor for readability, and a review checklist item for schema resilience.