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

fix bug with broken parsing of JSON patches #873

Closed mhl closed 8 years ago

mhl commented 8 years ago

If you just reorder items in an 3 item array, then the JSON patch that is generated might be something like the following:

=======
op: add
path: /other_names/0
value: {u'note': u'', u'name': u'Joey', u'end_date': u'', u'start_date': u''}
=======
op: remove
path: /other_names/3

The idea is that these operations are applied in order; first the new item is inserted at the start, then the fourth item, at index 3, is removed.

However, the JSON patch isn't used like that in candidates/diffs.py - it tries to look up other_names/3 in the original data, which gives this error:

JsonPointerException: index '3' is out of bounds

Instead, it should apply the earlier operations before trying to parse the later ones.

This error is causing some person pages to error.

mhl commented 8 years ago

There's a failing test for this in the 873-broken-jsonpatch-parsing branch (PR here: https://github.com/mysociety/yournextrepresentative/pull/874)