prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Improper exception handling in manage.py
  **Describe the bug**
  Exceptions are not handled properly in `initialize_db` method of `manage` module.
  
  **To Reproduce**
  Steps to reproduce the behavior:
  1. Open 'manage.py'
  2. See https://github.com/fossasia/open-event-server/blob/05cbd1abee0d81dd24d701420c3530e3b9bd645f/manage.py#L77
  
  **Expected behavior**
  It should follow standard exception handling format using `Exception` class.
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `manage.py`
  Content:
  ```
  1 import os
  2 
  3 from app.api.helpers.db import save_to_db
  4 from app.models.event import Event, get_new_event_identifier
  5 from app import manager
  6 from app import current_app as app
  7 from app.models import db
  8 from app.models.speaker import Speaker
  9 from populate_db import populate
  10 from flask_migrate import stamp
  11 from sqlalchemy.engine import reflection
  12 
  13 from tests.unittests.auth_helper import create_super_admin
  14 
  15 
  16 @manager.command
  17 def list_routes():
  18     import urllib
  19 
  20     output = []
  21     for rule in app.url_map.iter_rules():
  22         methods = ','.join(rule.methods)
  23         line = urllib.unquote("{:50s} {:20s} {}".format(
  24             rule.endpoint, methods, rule))
  25         output.append(line)
  26 
  27     for line in sorted(output):
  28         print(line)
  29 
  30 
  31 @manager.command
  32 def add_event_identifier():
  33     events = Event.query.all()
  34     for event in events:
  35         event.identifier = get_new_event_identifier()
  36         save_to_db(event)
  37 
  38 
  39 @manager.option('-e', '--event', help='Event ID. Eg. 1')
  40 def fix_speaker_images(event):
  41     from app.helpers.sessions_speakers.speakers import speaker_image_sizes
  42     from app.helpers.sessions_speakers.speakers import save_resized_photo
  43     import urllib
  44     from app.helpers.storage import generate_hash
  45     event_id = int(event)
  46     image_sizes = speaker_image_sizes()
  47     speakers = Speaker.query.filter_by(event_id=event_id).all()
  48     for speaker in speakers:
  49         if speaker.photo and speaker.photo.strip() != '':
  50             file_relative_path = 'static/media/temp/' + generate_hash(str(speaker.id)) + '.jpg'
  51             file_path = app.config['BASE_DIR'] + '/' + file_relative_path
  52             urllib.urlretrieve(speaker.photo, file_path)
  53             speaker.small = save_resized_photo(file_path, event_id, speaker.id, 'small', image_sizes)
  54             speaker.thumbnail = save_resized_photo(file_path, event_id, speaker.id, 'thumbnail', image_sizes)
  55             speaker.icon = save_resized_photo(file_path, event_id, speaker.id, 'icon', image_sizes)
  56             db.session.add(speaker)
  57             os.remove(file_path)
  58             print("Downloaded " + speaker.photo + " into " + file_relative_path)
  59         print("Processed - " + str(speaker.id))
  60     db.session.commit()
  61 
  62 
  63 @manager.option('-c', '--credentials', help='Super admin credentials. Eg. username:password')
  64 def initialize_db(credentials):
  65     with app.app_context():
  66         populate_data = True
  67         inspector = reflection.Inspector.from_engine(db.engine)
  68         table_name = 'events'
  69         table_names = inspector.get_table_names()
  70         print("[LOG] Existing tables:")
  71         print("[LOG] " + ','.join(table_names))
  72         if table_name not in table_names:
  73             print("[LOG] Table not found. Attempting creation")
  74             try:
  75                 db.create_all()
  76                 stamp()
  77             except:
  78                 populate_data = False
  79                 print("[LOG] Could not create tables. Either database does not exist or tables already created")
  80             if populate_data:
  81                 credentials = credentials.split(":")
  82                 create_super_admin(credentials[0], credentials[1])
  83                 populate()
  84         else:
  85             print("[LOG] Tables already exist. Skipping data population & creation.")
  86 
  87 
  88 @manager.command
  89 def prepare_kubernetes_db():
  90     with app.app_context():
  91         initialize_db('open_event_test_user@fossasia.org:fossasia')
  92 
  93 
  94 if __name__ == "__main__":
  95     manager.run()
  96
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/manage.py b/manage.py
  --- a/manage.py
  +++ b/manage.py
  @@ -74,7 +74,7 @@
               try:
                   db.create_all()
                   stamp()
  -            except:
  +            except Exception:
                   populate_data = False
                   print("[LOG] Could not create tables. Either database does not exist or tables already created")
               if populate_data:
  
verification_info: {"golden_diff": "diff --git a/manage.py b/manage.py\n--- a/manage.py\n+++ b/manage.py\n@@ -74,7 +74,7 @@\n             try:\n                 db.create_all()\n                 stamp()\n-            except:\n+            except Exception:\n                 populate_data = False\n                 print(\"[LOG] Could not create tables. Either database does not exist or tables already created\")\n             if populate_data:\n", "issue": "Improper exception handling in manage.py\n**Describe the bug**\r\nExceptions are not handled properly in `initialize_db` method of `manage` module.\r\n\r\n**To Reproduce**\r\nSteps to reproduce the behavior:\r\n1. Open 'manage.py'\r\n2. See https://github.com/fossasia/open-event-server/blob/05cbd1abee0d81dd24d701420c3530e3b9bd645f/manage.py#L77\r\n\r\n**Expected behavior**\r\nIt should follow standard exception handling format using `Exception` class.\n", "before_files": [{"content": "import os\n\nfrom app.api.helpers.db import save_to_db\nfrom app.models.event import Event, get_new_event_identifier\nfrom app import manager\nfrom app import current_app as app\nfrom app.models import db\nfrom app.models.speaker import Speaker\nfrom populate_db import populate\nfrom flask_migrate import stamp\nfrom sqlalchemy.engine import reflection\n\nfrom tests.unittests.auth_helper import create_super_admin\n\n\n@manager.command\ndef list_routes():\n    import urllib\n\n    output = []\n    for rule in app.url_map.iter_rules():\n        methods = ','.join(rule.methods)\n        line = urllib.unquote(\"{:50s} {:20s} {}\".format(\n            rule.endpoint, methods, rule))\n        output.append(line)\n\n    for line in sorted(output):\n        print(line)\n\n\n@manager.command\ndef add_event_identifier():\n    events = Event.query.all()\n    for event in events:\n        event.identifier = get_new_event_identifier()\n        save_to_db(event)\n\n\n@manager.option('-e', '--event', help='Event ID. Eg. 1')\ndef fix_speaker_images(event):\n    from app.helpers.sessions_speakers.speakers import speaker_image_sizes\n    from app.helpers.sessions_speakers.speakers import save_resized_photo\n    import urllib\n    from app.helpers.storage import generate_hash\n    event_id = int(event)\n    image_sizes = speaker_image_sizes()\n    speakers = Speaker.query.filter_by(event_id=event_id).all()\n    for speaker in speakers:\n        if speaker.photo and speaker.photo.strip() != '':\n            file_relative_path = 'static/media/temp/' + generate_hash(str(speaker.id)) + '.jpg'\n            file_path = app.config['BASE_DIR'] + '/' + file_relative_path\n            urllib.urlretrieve(speaker.photo, file_path)\n            speaker.small = save_resized_photo(file_path, event_id, speaker.id, 'small', image_sizes)\n            speaker.thumbnail = save_resized_photo(file_path, event_id, speaker.id, 'thumbnail', image_sizes)\n            speaker.icon = save_resized_photo(file_path, event_id, speaker.id, 'icon', image_sizes)\n            db.session.add(speaker)\n            os.remove(file_path)\n            print(\"Downloaded \" + speaker.photo + \" into \" + file_relative_path)\n        print(\"Processed - \" + str(speaker.id))\n    db.session.commit()\n\n\n@manager.option('-c', '--credentials', help='Super admin credentials. Eg. username:password')\ndef initialize_db(credentials):\n    with app.app_context():\n        populate_data = True\n        inspector = reflection.Inspector.from_engine(db.engine)\n        table_name = 'events'\n        table_names = inspector.get_table_names()\n        print(\"[LOG] Existing tables:\")\n        print(\"[LOG] \" + ','.join(table_names))\n        if table_name not in table_names:\n            print(\"[LOG] Table not found. Attempting creation\")\n            try:\n                db.create_all()\n                stamp()\n            except:\n                populate_data = False\n                print(\"[LOG] Could not create tables. Either database does not exist or tables already created\")\n            if populate_data:\n                credentials = credentials.split(\":\")\n                create_super_admin(credentials[0], credentials[1])\n                populate()\n        else:\n            print(\"[LOG] Tables already exist. Skipping data population & creation.\")\n\n\n@manager.command\ndef prepare_kubernetes_db():\n    with app.app_context():\n        initialize_db('open_event_test_user@fossasia.org:fossasia')\n\n\nif __name__ == \"__main__\":\n    manager.run()\n", "path": "manage.py"}], "after_files": [{"content": "import os\n\nfrom app.api.helpers.db import save_to_db\nfrom app.models.event import Event, get_new_event_identifier\nfrom app import manager\nfrom app import current_app as app\nfrom app.models import db\nfrom app.models.speaker import Speaker\nfrom populate_db import populate\nfrom flask_migrate import stamp\nfrom sqlalchemy.engine import reflection\n\nfrom tests.unittests.auth_helper import create_super_admin\n\n\n@manager.command\ndef list_routes():\n    import urllib\n\n    output = []\n    for rule in app.url_map.iter_rules():\n        methods = ','.join(rule.methods)\n        line = urllib.unquote(\"{:50s} {:20s} {}\".format(\n            rule.endpoint, methods, rule))\n        output.append(line)\n\n    for line in sorted(output):\n        print(line)\n\n\n@manager.command\ndef add_event_identifier():\n    events = Event.query.all()\n    for event in events:\n        event.identifier = get_new_event_identifier()\n        save_to_db(event)\n\n\n@manager.option('-e', '--event', help='Event ID. Eg. 1')\ndef fix_speaker_images(event):\n    from app.helpers.sessions_speakers.speakers import speaker_image_sizes\n    from app.helpers.sessions_speakers.speakers import save_resized_photo\n    import urllib\n    from app.helpers.storage import generate_hash\n    event_id = int(event)\n    image_sizes = speaker_image_sizes()\n    speakers = Speaker.query.filter_by(event_id=event_id).all()\n    for speaker in speakers:\n        if speaker.photo and speaker.photo.strip() != '':\n            file_relative_path = 'static/media/temp/' + generate_hash(str(speaker.id)) + '.jpg'\n            file_path = app.config['BASE_DIR'] + '/' + file_relative_path\n            urllib.urlretrieve(speaker.photo, file_path)\n            speaker.small = save_resized_photo(file_path, event_id, speaker.id, 'small', image_sizes)\n            speaker.thumbnail = save_resized_photo(file_path, event_id, speaker.id, 'thumbnail', image_sizes)\n            speaker.icon = save_resized_photo(file_path, event_id, speaker.id, 'icon', image_sizes)\n            db.session.add(speaker)\n            os.remove(file_path)\n            print(\"Downloaded \" + speaker.photo + \" into \" + file_relative_path)\n        print(\"Processed - \" + str(speaker.id))\n    db.session.commit()\n\n\n@manager.option('-c', '--credentials', help='Super admin credentials. Eg. username:password')\ndef initialize_db(credentials):\n    with app.app_context():\n        populate_data = True\n        inspector = reflection.Inspector.from_engine(db.engine)\n        table_name = 'events'\n        table_names = inspector.get_table_names()\n        print(\"[LOG] Existing tables:\")\n        print(\"[LOG] \" + ','.join(table_names))\n        if table_name not in table_names:\n            print(\"[LOG] Table not found. Attempting creation\")\n            try:\n                db.create_all()\n                stamp()\n            except Exception:\n                populate_data = False\n                print(\"[LOG] Could not create tables. Either database does not exist or tables already created\")\n            if populate_data:\n                credentials = credentials.split(\":\")\n                create_super_admin(credentials[0], credentials[1])\n                populate()\n        else:\n            print(\"[LOG] Tables already exist. Skipping data population & creation.\")\n\n\n@manager.command\ndef prepare_kubernetes_db():\n    with app.app_context():\n        initialize_db('open_event_test_user@fossasia.org:fossasia')\n\n\nif __name__ == \"__main__\":\n    manager.run()\n", "path": "manage.py"}]}