diff options
-rw-r--r-- | db.py | 1 | ||||
-rw-r--r-- | pastepy.py | 8 |
2 files changed, 7 insertions, 2 deletions
@@ -1,6 +1,7 @@ from sqlalchemy import create_engine, Column, Integer, String, DateTime, Text, Index, ForeignKey from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import sessionmaker, relation, backref +from sqlalchemy.orm.exc import NoResultFound import settings engine = create_engine(settings.db_path) @@ -120,8 +120,12 @@ class Paste(object): try: cache = session.query(db.Cache).filter_by(paste_hash = hash).one() paste = cache.paste - except: # No cache found, generate it. - paste = session.query(db.Paste).filter_by(hash = hash).one() + except db.NoResultFound: # No cache found, generate it. + try: + paste = session.query(db.Paste).filter_by(hash = hash).one() + except db.NoResultFound: + self.start_response('404 Not Found', []) + return [] try: lexername, text = get_formatted(paste.syntax, paste.text if type(paste.text) == unicode else paste.text.decode('utf8')) except: |