Permalink
Browse files

Stop crashes in some error cases.

web.ctx.features and context.features was not initialized in some cases
and the app was crashing because of that. Added support for context
defaults to avoid getting into that situation.
  • Loading branch information...
1 parent c88302a commit 4515cb96415e5198d8c02c837f8f37aa8babf886 Anand Chitipothu committed Apr 19, 2012
Showing with 9 additions and 1 deletion.
  1. +8 −0 openlibrary/plugins/openlibrary/code.py
  2. +1 −1 openlibrary/plugins/upstream/utils.py
View
8 openlibrary/plugins/openlibrary/code.py
@@ -793,6 +793,13 @@ def setup_logging():
print >> sys.stderr, "Unable to set logging configuration:", str(e)
raise
+def setup_context_defaults():
+ from infogami.utils import context
+ context.defaults.update({
+ 'features': [],
+ 'user': None
+ })
+
def setup():
import home, inlibrary, borrow_home, libraries, stats, support, events, status, merge_editions, authors
@@ -817,6 +824,7 @@ def setup():
import dev_instance
dev_instance.setup()
+ setup_context_defaults()
setup_template_globals()
setup_logging()
logger = logging.getLogger("openlibrary")
View
2 openlibrary/plugins/upstream/utils.py
@@ -580,7 +580,7 @@ def render(c):
@public
def get_random_recent_changes(n):
- if "recentchanges_v2" in web.ctx.features:
+ if "recentchanges_v2" in web.ctx.get("features", []):
changes = _get_recent_changes2()
else:
changes = _get_recent_changes()

0 comments on commit 4515cb9

Please sign in to comment.