mysociety / yournextrepresentative

A website for crowd-sourcing structured election candidate data
https://candidates.democracyclub.org.uk/
GNU Affero General Public License v3.0
56 stars 21 forks source link

On merging / reverting remove Memberships as well as MembershipExtras #867

Closed mhl closed 8 years ago

mhl commented 8 years ago

This was a bug - the revert_person_from_version_data method, which was used to implement merges of two candidates as well as reverting them to an earlier version, deletes all existing candidacies of a person and then recreates the ones that should be there. However, the code was only actually removing the MembershipExtra objects and leaving the Membership objects in the database. These weren't shown on the user-facing site because of missing the MembershipExtra objects, but would be shown in the API output which was causing confusion.

This commit fixes that problem; a delete on the Membership queryset deletes the corresponding MembershipExtras too.

Thanks to Sym Roe (@symroe) for spotting this and figuring out that it related to merging.

Fixes #866

struan commented 8 years ago

This looks good to me.