Debug Failing Tests in a Django Movie Search and Filter API
Company: Amazon
Role: Software Engineer
Category: Software Engineering Fundamentals
Difficulty: hard
Interview Round: Online Assessment
You are given an existing Django project that serves a movie catalog API, together with a suite of automated tests, several of which fail. You have 60 minutes to make the failing tests pass by fixing the application code. You are not asked to build anything in Django from scratch.
The tests exercise endpoints that accept an optional free-text search query, filters on fields such as genre, director, writer, rating and year, and a required order for the returned results. Treat the tests as the specification. The work is to find and fix the defects in routing, request handling, querying and response building that make them fail.
### Constraints and Clarifications
- The models, URL configuration, views and tests already exist.
- Fix application code. Assume the tests are correct unless one clearly contradicts the others.
- You can run the whole suite and individual tests locally.
### Clarifying Questions
- Are the tests the full specification, or is there also a written description of the endpoints?
- May tests be modified, or only application code?
- When a filter value is invalid (for example, a non-numeric year), should the endpoint return an error status or ignore the filter?
- Are text filters such as genre exact or case-insensitive matches, and are rating and year bounds inclusive? Where would you look in the tests to find out?
### Part 1 — Triage the failures
You run the suite and see failures spread over several endpoints: some are assertion failures and some are HTTP 500 responses. Before editing anything, how do you organize the failures, and in what order do you trace a single failing test through the code?
```hint Follow the request
Trace a failing request the way Django handles it, from the URL it hits to the response it returns. Ask at which layer the behavior first diverges from what the test expects.
```
#### What This Part Should Cover
- Grouping failures by endpoint and shared root cause before fixing anything
- A layer-by-layer trace order from the test to the response
- Which failures to fix first, and why
### Part 2 — Wrong or missing results
For each symptom below, explain what you would check and what the likely defects are:
1. A request with filters but no search query returns no results or an error, while the same filters with a query work.
2. Filtering by genre, director or writer returns the wrong movies, or returns some movies more than once.
3. Movies whose rating or year sits exactly on a filter boundary are missing or wrongly included.
4. A filter seems to be ignored entirely.
```hint Parameters and querysets
Read how the view pulls each parameter out of the request and how each filter is added to the queryset. Then compare every lookup path with the actual model fields and relations.
```
#### What This Part Should Cover
- Parameter extraction and type conversion
- Composing optional filters on a queryset
- Lookup paths through relations, and duplicate rows caused by joins
- Boundary semantics for numeric filters
### Part 3 — Ordering and server errors
The number of results is now right, but some tests still fail on the order of the results, and one endpoint returns HTTP 500. How do you find and fix each problem?
```hint Determinism and tracebacks
Ask what decides the order of two movies that tie on the primary sort key. For the 500, start from the exception at the end of the traceback and walk up to the first frame in the project's own code.
```
#### What This Part Should Cover
- An explicit sort with tie-breakers that match the tests
- Reading a traceback to find the failing layer
- Turning invalid input into a client error instead of a crash
### What a Strong Answer Covers
- A systematic, layered debugging process instead of trial-and-error edits
- Correct Django mechanics: URL routing, `request.GET`, queryset composition, field lookups and `order_by`
- Fixing each root cause once, rather than patching tests one by one
- Rerunning the full suite after each fix to catch regressions
- Time management across the 60-minute window
### Follow-up Questions
- One failing test seems to contradict another. How do you decide which behavior is intended?
- How would you check that your fix does not make the endpoint issue extra database queries per returned movie?
- What tests would you add so that these bugs cannot come back?
Overview: Debug an existing Django movie catalog API whose automated tests fail, covering URL routing, query parameter handling, queryset filters on genre, director, writer, rating and year, result ordering with tie-breakers, and HTTP 500 errors. It tests a systematic, layer-by-layer debugging process under a time limit.
Read the full Amazon Software Engineer interview experience this question came from