prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  User order_expiry_time as the parameter to expire orders
  **Describe the bug**
  Currently we are expiring orders after 10 minutes. We should change it to order_expiry_time parameter. 
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `app/api/helpers/order.py`
  Content:
  ```
  1 import logging
  2 from datetime import timedelta, datetime, timezone
  3 
  4 from flask import render_template
  5 
  6 from app.api.helpers import ticketing
  7 from app.api.helpers.db import save_to_db, safe_query_without_soft_deleted_entries, get_count
  8 from app.api.helpers.exceptions import UnprocessableEntity, ConflictException
  9 from app.api.helpers.files import create_save_pdf
  10 from app.api.helpers.storage import UPLOAD_PATHS
  11 from app.models import db
  12 from app.models.ticket import Ticket
  13 from app.models.ticket_holder import TicketHolder
  14 
  15 
  16 def delete_related_attendees_for_order(order):
  17     """
  18     Delete the associated attendees of an order when it is cancelled/deleted/expired
  19     :param order: Order whose attendees have to be deleted.
  20     :return:
  21     """
  22     for ticket_holder in order.ticket_holders:
  23         db.session.delete(ticket_holder)
  24         try:
  25             db.session.commit()
  26         except Exception as e:
  27             logging.error('DB Exception! %s' % e)
  28             db.session.rollback()
  29 
  30 
  31 def set_expiry_for_order(order, override=False):
  32     """
  33     Expire the order after the time slot(10 minutes) if the order is pending.
  34     Also expires the order if we want to expire an order regardless of the state and time.
  35     :param order: Order to be expired.
  36     :param override: flag to force expiry.
  37     :return:
  38     """
  39     if order and not order.paid_via and (override or (order.status == 'pending' and (
  40                 order.created_at +
  41                 timedelta(minutes=ticketing.TicketingManager.get_order_expiry())) < datetime.now(timezone.utc))):
  42             order.status = 'expired'
  43             delete_related_attendees_for_order(order)
  44             save_to_db(order)
  45     return order
  46 
  47 
  48 def create_pdf_tickets_for_holder(order):
  49     """
  50     Create tickets for the holders of an order.
  51     :param order: The order for which to create tickets for.
  52     """
  53     if order.status == 'completed':
  54         pdf = create_save_pdf(render_template('pdf/ticket_purchaser.html', order=order),
  55                               UPLOAD_PATHS['pdf']['ticket_attendee'],
  56                               dir_path='/static/uploads/pdf/tickets/')
  57         order.tickets_pdf_url = pdf
  58 
  59         for holder in order.ticket_holders:
  60             if (not holder.user) or holder.user.id != order.user_id:
  61                 # holder is not the order buyer.
  62                 pdf = create_save_pdf(render_template('pdf/ticket_attendee.html', order=order, holder=holder),
  63                                       UPLOAD_PATHS['pdf']['ticket_attendee'],
  64                                       dir_path='/static/uploads/pdf/tickets/')
  65             else:
  66                 # holder is the order buyer.
  67                 pdf = order.tickets_pdf_url
  68             holder.pdf_url = pdf
  69             save_to_db(holder)
  70 
  71         save_to_db(order)
  72 
  73 
  74 def create_onsite_attendees_for_order(data):
  75     """
  76     Creates on site ticket holders for an order and adds it into the request data.
  77     :param data: data initially passed in the POST request for order.
  78     :return:
  79     """
  80     on_site_tickets = data.get('on_site_tickets')
  81 
  82     if not on_site_tickets:
  83         raise UnprocessableEntity({'pointer': 'data/attributes/on_site_tickets'}, 'on_site_tickets info missing')
  84 
  85     data['ticket_holders'] = []
  86 
  87     for on_site_ticket in on_site_tickets:
  88         ticket_id = on_site_ticket['id']
  89         quantity = int(on_site_ticket['quantity'])
  90 
  91         ticket = safe_query_without_soft_deleted_entries(db, Ticket, 'id', ticket_id, 'ticket_id')
  92 
  93         ticket_sold_count = get_count(db.session.query(TicketHolder.id).
  94                                       filter_by(ticket_id=int(ticket.id), deleted_at=None))
  95 
  96         # Check if the ticket is already sold out or not.
  97         if ticket_sold_count + quantity > ticket.quantity:
  98             # delete the already created attendees.
  99             for holder in data['ticket_holders']:
  100                 ticket_holder = db.session.query(TicketHolder).filter(id == int(holder)).one()
  101                 db.session.delete(ticket_holder)
  102                 try:
  103                     db.session.commit()
  104                 except Exception as e:
  105                     logging.error('DB Exception! %s' % e)
  106                     db.session.rollback()
  107 
  108             raise ConflictException(
  109                 {'pointer': '/data/attributes/on_site_tickets'},
  110                 "Ticket with id: {} already sold out. You can buy at most {} tickets".format(ticket_id,
  111                                                                                              ticket.quantity -
  112                                                                                              ticket_sold_count)
  113             )
  114 
  115         for _ in range(1, quantity):
  116             ticket_holder = TicketHolder(firstname='onsite', lastname='attendee', email='example@example.com',
  117                                          ticket_id=ticket.id, event_id=data.get('event'))
  118             save_to_db(ticket_holder)
  119             data['ticket_holders'].append(ticket_holder.id)
  120 
  121     # delete from the data.
  122     del data['on_site_tickets']
  123
  ```
  --- 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/app/api/helpers/order.py b/app/api/helpers/order.py
  --- a/app/api/helpers/order.py
  +++ b/app/api/helpers/order.py
  @@ -38,7 +38,7 @@
       """
       if order and not order.paid_via and (override or (order.status == 'pending' and (
                   order.created_at +
  -                timedelta(minutes=ticketing.TicketingManager.get_order_expiry())) < datetime.now(timezone.utc))):
  +                timedelta(minutes=order.event.order_expiry_time)) < datetime.now(timezone.utc))):
               order.status = 'expired'
               delete_related_attendees_for_order(order)
               save_to_db(order)
  
verification_info: {"golden_diff": "diff --git a/app/api/helpers/order.py b/app/api/helpers/order.py\n--- a/app/api/helpers/order.py\n+++ b/app/api/helpers/order.py\n@@ -38,7 +38,7 @@\n     \"\"\"\n     if order and not order.paid_via and (override or (order.status == 'pending' and (\n                 order.created_at +\n-                timedelta(minutes=ticketing.TicketingManager.get_order_expiry())) < datetime.now(timezone.utc))):\n+                timedelta(minutes=order.event.order_expiry_time)) < datetime.now(timezone.utc))):\n             order.status = 'expired'\n             delete_related_attendees_for_order(order)\n             save_to_db(order)\n", "issue": "User order_expiry_time as the parameter to expire orders\n**Describe the bug**\r\nCurrently we are expiring orders after 10 minutes. We should change it to order_expiry_time parameter. \n", "before_files": [{"content": "import logging\nfrom datetime import timedelta, datetime, timezone\n\nfrom flask import render_template\n\nfrom app.api.helpers import ticketing\nfrom app.api.helpers.db import save_to_db, safe_query_without_soft_deleted_entries, get_count\nfrom app.api.helpers.exceptions import UnprocessableEntity, ConflictException\nfrom app.api.helpers.files import create_save_pdf\nfrom app.api.helpers.storage import UPLOAD_PATHS\nfrom app.models import db\nfrom app.models.ticket import Ticket\nfrom app.models.ticket_holder import TicketHolder\n\n\ndef delete_related_attendees_for_order(order):\n    \"\"\"\n    Delete the associated attendees of an order when it is cancelled/deleted/expired\n    :param order: Order whose attendees have to be deleted.\n    :return:\n    \"\"\"\n    for ticket_holder in order.ticket_holders:\n        db.session.delete(ticket_holder)\n        try:\n            db.session.commit()\n        except Exception as e:\n            logging.error('DB Exception! %s' % e)\n            db.session.rollback()\n\n\ndef set_expiry_for_order(order, override=False):\n    \"\"\"\n    Expire the order after the time slot(10 minutes) if the order is pending.\n    Also expires the order if we want to expire an order regardless of the state and time.\n    :param order: Order to be expired.\n    :param override: flag to force expiry.\n    :return:\n    \"\"\"\n    if order and not order.paid_via and (override or (order.status == 'pending' and (\n                order.created_at +\n                timedelta(minutes=ticketing.TicketingManager.get_order_expiry())) < datetime.now(timezone.utc))):\n            order.status = 'expired'\n            delete_related_attendees_for_order(order)\n            save_to_db(order)\n    return order\n\n\ndef create_pdf_tickets_for_holder(order):\n    \"\"\"\n    Create tickets for the holders of an order.\n    :param order: The order for which to create tickets for.\n    \"\"\"\n    if order.status == 'completed':\n        pdf = create_save_pdf(render_template('pdf/ticket_purchaser.html', order=order),\n                              UPLOAD_PATHS['pdf']['ticket_attendee'],\n                              dir_path='/static/uploads/pdf/tickets/')\n        order.tickets_pdf_url = pdf\n\n        for holder in order.ticket_holders:\n            if (not holder.user) or holder.user.id != order.user_id:\n                # holder is not the order buyer.\n                pdf = create_save_pdf(render_template('pdf/ticket_attendee.html', order=order, holder=holder),\n                                      UPLOAD_PATHS['pdf']['ticket_attendee'],\n                                      dir_path='/static/uploads/pdf/tickets/')\n            else:\n                # holder is the order buyer.\n                pdf = order.tickets_pdf_url\n            holder.pdf_url = pdf\n            save_to_db(holder)\n\n        save_to_db(order)\n\n\ndef create_onsite_attendees_for_order(data):\n    \"\"\"\n    Creates on site ticket holders for an order and adds it into the request data.\n    :param data: data initially passed in the POST request for order.\n    :return:\n    \"\"\"\n    on_site_tickets = data.get('on_site_tickets')\n\n    if not on_site_tickets:\n        raise UnprocessableEntity({'pointer': 'data/attributes/on_site_tickets'}, 'on_site_tickets info missing')\n\n    data['ticket_holders'] = []\n\n    for on_site_ticket in on_site_tickets:\n        ticket_id = on_site_ticket['id']\n        quantity = int(on_site_ticket['quantity'])\n\n        ticket = safe_query_without_soft_deleted_entries(db, Ticket, 'id', ticket_id, 'ticket_id')\n\n        ticket_sold_count = get_count(db.session.query(TicketHolder.id).\n                                      filter_by(ticket_id=int(ticket.id), deleted_at=None))\n\n        # Check if the ticket is already sold out or not.\n        if ticket_sold_count + quantity > ticket.quantity:\n            # delete the already created attendees.\n            for holder in data['ticket_holders']:\n                ticket_holder = db.session.query(TicketHolder).filter(id == int(holder)).one()\n                db.session.delete(ticket_holder)\n                try:\n                    db.session.commit()\n                except Exception as e:\n                    logging.error('DB Exception! %s' % e)\n                    db.session.rollback()\n\n            raise ConflictException(\n                {'pointer': '/data/attributes/on_site_tickets'},\n                \"Ticket with id: {} already sold out. You can buy at most {} tickets\".format(ticket_id,\n                                                                                             ticket.quantity -\n                                                                                             ticket_sold_count)\n            )\n\n        for _ in range(1, quantity):\n            ticket_holder = TicketHolder(firstname='onsite', lastname='attendee', email='example@example.com',\n                                         ticket_id=ticket.id, event_id=data.get('event'))\n            save_to_db(ticket_holder)\n            data['ticket_holders'].append(ticket_holder.id)\n\n    # delete from the data.\n    del data['on_site_tickets']\n", "path": "app/api/helpers/order.py"}], "after_files": [{"content": "import logging\nfrom datetime import timedelta, datetime, timezone\n\nfrom flask import render_template\n\nfrom app.api.helpers import ticketing\nfrom app.api.helpers.db import save_to_db, safe_query_without_soft_deleted_entries, get_count\nfrom app.api.helpers.exceptions import UnprocessableEntity, ConflictException\nfrom app.api.helpers.files import create_save_pdf\nfrom app.api.helpers.storage import UPLOAD_PATHS\nfrom app.models import db\nfrom app.models.ticket import Ticket\nfrom app.models.ticket_holder import TicketHolder\n\n\ndef delete_related_attendees_for_order(order):\n    \"\"\"\n    Delete the associated attendees of an order when it is cancelled/deleted/expired\n    :param order: Order whose attendees have to be deleted.\n    :return:\n    \"\"\"\n    for ticket_holder in order.ticket_holders:\n        db.session.delete(ticket_holder)\n        try:\n            db.session.commit()\n        except Exception as e:\n            logging.error('DB Exception! %s' % e)\n            db.session.rollback()\n\n\ndef set_expiry_for_order(order, override=False):\n    \"\"\"\n    Expire the order after the time slot(10 minutes) if the order is pending.\n    Also expires the order if we want to expire an order regardless of the state and time.\n    :param order: Order to be expired.\n    :param override: flag to force expiry.\n    :return:\n    \"\"\"\n    if order and not order.paid_via and (override or (order.status == 'pending' and (\n                order.created_at +\n                timedelta(minutes=order.event.order_expiry_time)) < datetime.now(timezone.utc))):\n            order.status = 'expired'\n            delete_related_attendees_for_order(order)\n            save_to_db(order)\n    return order\n\n\ndef create_pdf_tickets_for_holder(order):\n    \"\"\"\n    Create tickets for the holders of an order.\n    :param order: The order for which to create tickets for.\n    \"\"\"\n    if order.status == 'completed':\n        pdf = create_save_pdf(render_template('pdf/ticket_purchaser.html', order=order),\n                              UPLOAD_PATHS['pdf']['ticket_attendee'],\n                              dir_path='/static/uploads/pdf/tickets/')\n        order.tickets_pdf_url = pdf\n\n        for holder in order.ticket_holders:\n            if (not holder.user) or holder.user.id != order.user_id:\n                # holder is not the order buyer.\n                pdf = create_save_pdf(render_template('pdf/ticket_attendee.html', order=order, holder=holder),\n                                      UPLOAD_PATHS['pdf']['ticket_attendee'],\n                                      dir_path='/static/uploads/pdf/tickets/')\n            else:\n                # holder is the order buyer.\n                pdf = order.tickets_pdf_url\n            holder.pdf_url = pdf\n            save_to_db(holder)\n\n        save_to_db(order)\n\n\ndef create_onsite_attendees_for_order(data):\n    \"\"\"\n    Creates on site ticket holders for an order and adds it into the request data.\n    :param data: data initially passed in the POST request for order.\n    :return:\n    \"\"\"\n    on_site_tickets = data.get('on_site_tickets')\n\n    if not on_site_tickets:\n        raise UnprocessableEntity({'pointer': 'data/attributes/on_site_tickets'}, 'on_site_tickets info missing')\n\n    data['ticket_holders'] = []\n\n    for on_site_ticket in on_site_tickets:\n        ticket_id = on_site_ticket['id']\n        quantity = int(on_site_ticket['quantity'])\n\n        ticket = safe_query_without_soft_deleted_entries(db, Ticket, 'id', ticket_id, 'ticket_id')\n\n        ticket_sold_count = get_count(db.session.query(TicketHolder.id).\n                                      filter_by(ticket_id=int(ticket.id), deleted_at=None))\n\n        # Check if the ticket is already sold out or not.\n        if ticket_sold_count + quantity > ticket.quantity:\n            # delete the already created attendees.\n            for holder in data['ticket_holders']:\n                ticket_holder = db.session.query(TicketHolder).filter(id == int(holder)).one()\n                db.session.delete(ticket_holder)\n                try:\n                    db.session.commit()\n                except Exception as e:\n                    logging.error('DB Exception! %s' % e)\n                    db.session.rollback()\n\n            raise ConflictException(\n                {'pointer': '/data/attributes/on_site_tickets'},\n                \"Ticket with id: {} already sold out. You can buy at most {} tickets\".format(ticket_id,\n                                                                                             ticket.quantity -\n                                                                                             ticket_sold_count)\n            )\n\n        for _ in range(1, quantity):\n            ticket_holder = TicketHolder(firstname='onsite', lastname='attendee', email='example@example.com',\n                                         ticket_id=ticket.id, event_id=data.get('event'))\n            save_to_db(ticket_holder)\n            data['ticket_holders'].append(ticket_holder.id)\n\n    # delete from the data.\n    del data['on_site_tickets']\n", "path": "app/api/helpers/order.py"}]}