From 911cf430a921d16fd2f0ace5e619ea304f7ec770 Mon Sep 17 00:00:00 2001 From: Lisandro Date: Fri, 15 Jun 2018 08:30:44 -0300 Subject: [PATCH] Catch KeyError in download function This change is necessary to avoid an error ticket when you delete an upload field from a table (and also from the model definition). In those cases, requests to old URLs will throw a KeyError. With this fix, those requests return 404 as expected. Also, catching AttributeError is still necessary for the situation when the table is removed entirely. If an old request come in, that sentence will throw an AttributeError, that will be catched properly, and request will return 404. --- gluon/globals.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gluon/globals.py b/gluon/globals.py index 45862154..512f5761 100644 --- a/gluon/globals.py +++ b/gluon/globals.py @@ -667,7 +667,7 @@ class Response(Storage): (t, f) = (items.group('table'), items.group('field')) try: field = db[t][f] - except AttributeError: + except (AttributeError, KeyError): raise HTTP(404) try: (filename, stream) = field.retrieve(name, nameonly=True)