Page MenuHomePhabricator

Gracefully handle server errors on /applications/apply/<random_number>
Closed, ResolvedPublic

Description

When users apply for a partner that's either not available at the moment or not present on the system, handle the error gracefully instead of an internal server error (eg. https://wikipedialibrary.wmflabs.org/applications/apply/63/). While not available partners are invisible to non-staff users, they are still capable of entering the partner_ID into the URL (/applications/apply/<that_id>), which then results in a fatal error.

We're likely getting a partner directly by primary key somewhere without first checking whether that partner exists (and is available). We could use the get_object_or_404() function (https://docs.djangoproject.com/en/1.11/topics/http/shortcuts/#get-object-or-404) to avoid this issue, returning a 404 to the user instead of a server error.

Event Timeline

I would like to work on this task.
Can I get much more information regarding this task?

@rahul-kumi Awesome! I've added another couple of sentences explaining the likely cause of the error and a potential solution.

To get set up with the Library Card platform you should take a look at https://github.com/WikipediaLibrary/twlight_vagrant. We have a step-by-step guide in progress at https://github.com/Samwalton9/twlight_vagrant/blob/patch-1/docs/step_by_step.md for Windows users. For Linux users, it should be as simple as installing Vagrant and Virtualbox, cloning the repository, and skipping to step 10.

Let me know if you have further questions!

Hi @Samwalton9 , It looks like return type of

get_object_or_404()

is not a QuerySet and doesn't support the .count() method and would have created issue with

assert partners.count() == 1

, so I have opened a PR with a different approach. Could you please check it out here ?