Skip to content

Commit

Permalink
If we can't find a person/party match fallback to the current member
Browse files Browse the repository at this point in the history
This stops the importer from dying when it encounters the corner case
where we don't have a member record for a person in the right party.
It also means that some votes will be attributed to the incorrect
party, see #110.

Fixes #106
Fixes #107
  • Loading branch information
henare committed Nov 23, 2015
1 parent 047a641 commit 741b4b9
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/data_loader/ukraine/vote_events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,13 @@ def load!
votes.each do |v|
party_name = people.party_name_from_id(v["group_id"])
member = Member.current_on(division.date).find_by(person_id: v["voter_id"], party: party_name) ||
Member.find_by!(person_id: v["voter_id"], party: party_name) # Fallback when current_on isn't quite right
Member.find_by(person_id: v["voter_id"], party: party_name) # Fallback when current_on isn't quite right

if !member
Rails.logger.warn "Couldn't find voter #{v["voter_id"]} in party #{party_name}"
member = Member.current_on(division.date).find_by!(person_id: v["voter_id"])
end

vote = division.votes.find_or_initialize_by(member: member)
if option = popolo_to_publicwhip_vote(v["option"])
division.votes.create!(member: member, vote: option)
end
Expand Down

0 comments on commit 741b4b9

Please sign in to comment.