Skip to content
This repository has been archived by the owner on Dec 4, 2018. It is now read-only.

Handle missing diffs gracefully #835

Merged
merged 1 commit into from
Oct 20, 2017
Merged

Conversation

chosak
Copy link
Member

@chosak chosak commented Oct 2, 2017

This commit fixes a 500 error that's caused by trying to hit an invalid or missing diff, e.g. one where the node requested is in neither of the two versions being diffed. An example URL that can be hit locally for Reg B is

http://localhost:8000/eregulations/diff/1002-99/2013-22752_20140101/2013-22752_20140118?from_version=2013-22752_20140118

This node doesn't exist in either of the two (unlike 1002-1, which does), and currently causes a KeyError by looking for a missing label field in a generated node, which is actually empty.

This change detects if the built tree is empty, and, if so, just raises a 404 error instead.

Unfortunately, while it'd be nice to add unit tests for this, it's a little bit tricky because of the way this code is written. It'd require a larger refactor to write a test for this. This can be tested manually using the URL above.

This commit fixes a 500 error that's caused by trying to hit an invalid
or missing diff, e.g. one where the node requested is in neither of the
two versions being diffed. An example URL that can be hit locally for
Reg B is

http://localhost:8000/eregulations/diff/1002-99/2013-22752_20140101/2013-22752_20140118?from_version=2013-22752_20140118

This node doesn't exist in either of the two (unlike `1002-1`, which
does), and currently causes a `KeyError` by looking for a missing
`label` field in a generated node, which is actually empty.

This change detects if the built tree is empty, and, if so, just raises
a 404 error instead.

Unfortunately, while it'd be nice to add unit tests for this, it's a
little bit tricky because of the way this code is written. It'd require
a larger refactor to write a test for this. This can be tested manually
using the URL above.
@grapesmoker grapesmoker merged commit 0c4ca9a into master Oct 20, 2017
Copy link
Contributor

@grapesmoker grapesmoker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@chosak chosak deleted the handle-missing-diffs-gracefully branch October 24, 2017 13:18
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants