The Neighborhood model has a foreign key to AnalysisJob to keep track of the latest job for each neighborhood. But the on_delete property of that foreign key was set to CASCADE, so deleting a job would take the neighborhood with it. Which is not what we want. This changes it to SET_NULL, i.e. if the job that's currently the "last job" of a neighborhood gets deleted, the last_job on that neighborhood gets set to NULL and the neighborhood is fine.
I looked into this while I was evaluating issues for prioritization and decided this one was too simple, and the consequences of triggering the bug too troublesome, not to just do. So I just did it.
Testing Instructions
Run migrations
Make at least one neighborhood and job (e.g. by importing a batch)
Go into the Django shell and delete any or all of the jobs for a given neighborhood.
The neighborhood should still be there. If you deleted the job that was set as last_job for the neighborhood, that field will now be null/None.
Overview
The Neighborhood model has a foreign key to AnalysisJob to keep track of the latest job for each neighborhood. But the
on_delete
property of that foreign key was set toCASCADE
, so deleting a job would take the neighborhood with it. Which is not what we want. This changes it toSET_NULL
, i.e. if the job that's currently the "last job" of a neighborhood gets deleted, thelast_job
on that neighborhood gets set to NULL and the neighborhood is fine.Demo
Before:
After:
Notes
I looked into this while I was evaluating issues for prioritization and decided this one was too simple, and the consequences of triggering the bug too troublesome, not to just do. So I just did it.
Testing Instructions
last_job
for the neighborhood, that field will now be null/None.Checklist
Resolves #644