prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  copied events have no organizer
  **Describe the bug**
  <!-- A clear and concise description of what the bug is. -->
  Currently, copied events have no associated event roles and are being showed with no organizers
  
  **To Reproduce**
  Steps to reproduce the behavior:
  1. Go to any event
  2. Click on copy
  3. Go to Admin/Events 
  4. See error
  
  ![screenshot from 2019-02-20 15-53-44](https://user-images.githubusercontent.com/21087061/53084979-eb593700-3527-11e9-86a5-1a5c868d3db5.png)
  
  **Expected behavior**
  <!-- A clear and concise description of what you expected to happen. -->
  The copied event should also be organized by previous organiser himself
  
  **Additional details (please complete the following information):**
   - OS: [e.g. MacOS, Ubuntu, CentOS] Ubuntu
   - Python Version [e.g. `3.5`, `3.6`] 3.5
  
  **Additional context**
  <!-- Add any other context about the problem here. -->
  Working on it
  
  --- 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/event_copy.py`
  Content:
  ```
  1 from flask import jsonify, Blueprint, abort, make_response
  2 from sqlalchemy.orm import make_transient
  3 
  4 from app.api.helpers.db import safe_query
  5 from app.api.helpers.files import create_save_resized_image
  6 from app.api.helpers.permission_manager import has_access
  7 from app.models.custom_form import CustomForms
  8 from app.models.discount_code import DiscountCode
  9 from app.models.event import Event, get_new_event_identifier
  10 from app.models import db
  11 from app.models.microlocation import Microlocation
  12 from app.models.social_link import SocialLink
  13 from app.models.speakers_call import SpeakersCall
  14 from app.models.sponsor import Sponsor
  15 from app.models.ticket import Ticket
  16 from app.models.track import Track
  17 
  18 event_copy = Blueprint('event_copy', __name__, url_prefix='/v1/events')
  19 
  20 
  21 @event_copy.route('/<identifier>/copy', methods=['POST'])
  22 def create_event_copy(identifier):
  23     id = 'identifier'
  24 
  25     if identifier.isdigit():
  26         id = 'id'
  27 
  28     event = safe_query(db, Event, id, identifier, 'event_' + id)
  29 
  30     if not has_access('is_coorganizer', event_id=event.id):
  31         return abort(
  32             make_response(jsonify(error="Access Forbidden"), 403)
  33         )
  34     tickets = Ticket.query.filter_by(event_id=event.id).all()
  35     social_links = SocialLink.query.filter_by(event_id=event.id).all()
  36     sponsors = Sponsor.query.filter_by(event_id=event.id).all()
  37     microlocations = Microlocation.query.filter_by(event_id=event.id).all()
  38     tracks = Track.query.filter_by(event_id=event.id).all()
  39     custom_forms = CustomForms.query.filter_by(event_id=event.id).all()
  40     discount_codes = DiscountCode.query.filter_by(event_id=event.id).all()
  41     speaker_calls = SpeakersCall.query.filter_by(event_id=event.id).all()
  42 
  43     db.session.expunge(event)  # expunge the object from session
  44     make_transient(event)
  45     delattr(event, 'id')
  46     event.identifier = get_new_event_identifier()
  47     db.session.add(event)
  48     db.session.commit()
  49 
  50     # Removes access_codes, order_tickets, ticket_tags for the new tickets created.
  51     for ticket in tickets:
  52         ticket_id = ticket.id
  53         db.session.expunge(ticket)  # expunge the object from session
  54         make_transient(ticket)
  55         ticket.event_id = event.id
  56         delattr(ticket, 'id')
  57         db.session.add(ticket)
  58         db.session.commit()
  59 
  60     for link in social_links:
  61         link_id = link.id
  62         db.session.expunge(link)  # expunge the object from session
  63         make_transient(link)
  64         link.event_id = event.id
  65         delattr(link, 'id')
  66         db.session.add(link)
  67         db.session.commit()
  68 
  69     for sponsor in sponsors:
  70         sponsor_id = sponsor.id
  71         db.session.expunge(sponsor)  # expunge the object from session
  72         make_transient(sponsor)
  73         sponsor.event_id = event.id
  74         logo_url = create_save_resized_image(image_file=sponsor.logo_url, resize=False)
  75         delattr(sponsor, 'id')
  76         sponsor.logo_url = logo_url
  77         db.session.add(sponsor)
  78         db.session.commit()
  79 
  80     for location in microlocations:
  81         location_id = location.id
  82         db.session.expunge(location)  # expunge the object from session
  83         make_transient(location)
  84         location.event_id = event.id
  85         delattr(location, 'id')
  86         db.session.add(location)
  87         db.session.commit()
  88 
  89     # No sessions are copied for new tracks
  90     for track in tracks:
  91         track_id = track.id
  92         db.session.expunge(track)  # expunge the object from session
  93         make_transient(track)
  94         track.event_id = event.id
  95         delattr(track, 'id')
  96         db.session.add(track)
  97         db.session.commit()
  98 
  99     for call in speaker_calls:
  100         call_id = call.id
  101         db.session.expunge(call)  # expunge the object from session
  102         make_transient(call)
  103         call.event_id = event.id
  104         delattr(call, 'id')
  105         db.session.add(call)
  106         db.session.commit()
  107 
  108     for code in discount_codes:
  109         code_id = code.id
  110         db.session.expunge(code)  # expunge the object from session
  111         make_transient(code)
  112         code.event_id = event.id
  113         delattr(code, 'id')
  114         db.session.add(code)
  115         db.session.commit()
  116 
  117     for form in custom_forms:
  118         form_id = form.id
  119         db.session.expunge(form)  # expunge the object from session
  120         make_transient(form)
  121         form.event_id = event.id
  122         delattr(form, 'id')
  123         db.session.add(form)
  124         db.session.commit()
  125 
  126     return jsonify({
  127         'id': event.id,
  128         'identifier': event.identifier,
  129         "copied": True
  130     })
  131
  ```
  --- 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/event_copy.py b/app/api/event_copy.py
  --- a/app/api/event_copy.py
  +++ b/app/api/event_copy.py
  @@ -14,6 +14,7 @@
   from app.models.sponsor import Sponsor
   from app.models.ticket import Ticket
   from app.models.track import Track
  +from app.models.users_events_role import UsersEventsRoles
   
   event_copy = Blueprint('event_copy', __name__, url_prefix='/v1/events')
   
  @@ -39,6 +40,7 @@
       custom_forms = CustomForms.query.filter_by(event_id=event.id).all()
       discount_codes = DiscountCode.query.filter_by(event_id=event.id).all()
       speaker_calls = SpeakersCall.query.filter_by(event_id=event.id).all()
  +    user_event_roles = UsersEventsRoles.query.filter_by(event_id=event.id).all()
   
       db.session.expunge(event)  # expunge the object from session
       make_transient(event)
  @@ -123,6 +125,14 @@
           db.session.add(form)
           db.session.commit()
   
  +    for user_role in user_event_roles:
  +        db.session.expunge(user_role)
  +        make_transient(user_role)
  +        user_role.event_id = event.id
  +        delattr(user_role, 'id')
  +        db.session.add(user_role)
  +        db.session.commit()
  +
       return jsonify({
           'id': event.id,
           'identifier': event.identifier,
  
verification_info: {"golden_diff": "diff --git a/app/api/event_copy.py b/app/api/event_copy.py\n--- a/app/api/event_copy.py\n+++ b/app/api/event_copy.py\n@@ -14,6 +14,7 @@\n from app.models.sponsor import Sponsor\n from app.models.ticket import Ticket\n from app.models.track import Track\n+from app.models.users_events_role import UsersEventsRoles\n \n event_copy = Blueprint('event_copy', __name__, url_prefix='/v1/events')\n \n@@ -39,6 +40,7 @@\n     custom_forms = CustomForms.query.filter_by(event_id=event.id).all()\n     discount_codes = DiscountCode.query.filter_by(event_id=event.id).all()\n     speaker_calls = SpeakersCall.query.filter_by(event_id=event.id).all()\n+    user_event_roles = UsersEventsRoles.query.filter_by(event_id=event.id).all()\n \n     db.session.expunge(event)  # expunge the object from session\n     make_transient(event)\n@@ -123,6 +125,14 @@\n         db.session.add(form)\n         db.session.commit()\n \n+    for user_role in user_event_roles:\n+        db.session.expunge(user_role)\n+        make_transient(user_role)\n+        user_role.event_id = event.id\n+        delattr(user_role, 'id')\n+        db.session.add(user_role)\n+        db.session.commit()\n+\n     return jsonify({\n         'id': event.id,\n         'identifier': event.identifier,\n", "issue": "copied events have no organizer\n**Describe the bug**\r\n<!-- A clear and concise description of what the bug is. -->\r\nCurrently, copied events have no associated event roles and are being showed with no organizers\r\n\r\n**To Reproduce**\r\nSteps to reproduce the behavior:\r\n1. Go to any event\r\n2. Click on copy\r\n3. Go to Admin/Events \r\n4. See error\r\n\r\n![screenshot from 2019-02-20 15-53-44](https://user-images.githubusercontent.com/21087061/53084979-eb593700-3527-11e9-86a5-1a5c868d3db5.png)\r\n\r\n**Expected behavior**\r\n<!-- A clear and concise description of what you expected to happen. -->\r\nThe copied event should also be organized by previous organiser himself\r\n\r\n**Additional details (please complete the following information):**\r\n - OS: [e.g. MacOS, Ubuntu, CentOS] Ubuntu\r\n - Python Version [e.g. `3.5`, `3.6`] 3.5\r\n\r\n**Additional context**\r\n<!-- Add any other context about the problem here. -->\r\nWorking on it\n", "before_files": [{"content": "from flask import jsonify, Blueprint, abort, make_response\nfrom sqlalchemy.orm import make_transient\n\nfrom app.api.helpers.db import safe_query\nfrom app.api.helpers.files import create_save_resized_image\nfrom app.api.helpers.permission_manager import has_access\nfrom app.models.custom_form import CustomForms\nfrom app.models.discount_code import DiscountCode\nfrom app.models.event import Event, get_new_event_identifier\nfrom app.models import db\nfrom app.models.microlocation import Microlocation\nfrom app.models.social_link import SocialLink\nfrom app.models.speakers_call import SpeakersCall\nfrom app.models.sponsor import Sponsor\nfrom app.models.ticket import Ticket\nfrom app.models.track import Track\n\nevent_copy = Blueprint('event_copy', __name__, url_prefix='/v1/events')\n\n\n@event_copy.route('/<identifier>/copy', methods=['POST'])\ndef create_event_copy(identifier):\n    id = 'identifier'\n\n    if identifier.isdigit():\n        id = 'id'\n\n    event = safe_query(db, Event, id, identifier, 'event_' + id)\n\n    if not has_access('is_coorganizer', event_id=event.id):\n        return abort(\n            make_response(jsonify(error=\"Access Forbidden\"), 403)\n        )\n    tickets = Ticket.query.filter_by(event_id=event.id).all()\n    social_links = SocialLink.query.filter_by(event_id=event.id).all()\n    sponsors = Sponsor.query.filter_by(event_id=event.id).all()\n    microlocations = Microlocation.query.filter_by(event_id=event.id).all()\n    tracks = Track.query.filter_by(event_id=event.id).all()\n    custom_forms = CustomForms.query.filter_by(event_id=event.id).all()\n    discount_codes = DiscountCode.query.filter_by(event_id=event.id).all()\n    speaker_calls = SpeakersCall.query.filter_by(event_id=event.id).all()\n\n    db.session.expunge(event)  # expunge the object from session\n    make_transient(event)\n    delattr(event, 'id')\n    event.identifier = get_new_event_identifier()\n    db.session.add(event)\n    db.session.commit()\n\n    # Removes access_codes, order_tickets, ticket_tags for the new tickets created.\n    for ticket in tickets:\n        ticket_id = ticket.id\n        db.session.expunge(ticket)  # expunge the object from session\n        make_transient(ticket)\n        ticket.event_id = event.id\n        delattr(ticket, 'id')\n        db.session.add(ticket)\n        db.session.commit()\n\n    for link in social_links:\n        link_id = link.id\n        db.session.expunge(link)  # expunge the object from session\n        make_transient(link)\n        link.event_id = event.id\n        delattr(link, 'id')\n        db.session.add(link)\n        db.session.commit()\n\n    for sponsor in sponsors:\n        sponsor_id = sponsor.id\n        db.session.expunge(sponsor)  # expunge the object from session\n        make_transient(sponsor)\n        sponsor.event_id = event.id\n        logo_url = create_save_resized_image(image_file=sponsor.logo_url, resize=False)\n        delattr(sponsor, 'id')\n        sponsor.logo_url = logo_url\n        db.session.add(sponsor)\n        db.session.commit()\n\n    for location in microlocations:\n        location_id = location.id\n        db.session.expunge(location)  # expunge the object from session\n        make_transient(location)\n        location.event_id = event.id\n        delattr(location, 'id')\n        db.session.add(location)\n        db.session.commit()\n\n    # No sessions are copied for new tracks\n    for track in tracks:\n        track_id = track.id\n        db.session.expunge(track)  # expunge the object from session\n        make_transient(track)\n        track.event_id = event.id\n        delattr(track, 'id')\n        db.session.add(track)\n        db.session.commit()\n\n    for call in speaker_calls:\n        call_id = call.id\n        db.session.expunge(call)  # expunge the object from session\n        make_transient(call)\n        call.event_id = event.id\n        delattr(call, 'id')\n        db.session.add(call)\n        db.session.commit()\n\n    for code in discount_codes:\n        code_id = code.id\n        db.session.expunge(code)  # expunge the object from session\n        make_transient(code)\n        code.event_id = event.id\n        delattr(code, 'id')\n        db.session.add(code)\n        db.session.commit()\n\n    for form in custom_forms:\n        form_id = form.id\n        db.session.expunge(form)  # expunge the object from session\n        make_transient(form)\n        form.event_id = event.id\n        delattr(form, 'id')\n        db.session.add(form)\n        db.session.commit()\n\n    return jsonify({\n        'id': event.id,\n        'identifier': event.identifier,\n        \"copied\": True\n    })\n", "path": "app/api/event_copy.py"}], "after_files": [{"content": "from flask import jsonify, Blueprint, abort, make_response\nfrom sqlalchemy.orm import make_transient\n\nfrom app.api.helpers.db import safe_query\nfrom app.api.helpers.files import create_save_resized_image\nfrom app.api.helpers.permission_manager import has_access\nfrom app.models.custom_form import CustomForms\nfrom app.models.discount_code import DiscountCode\nfrom app.models.event import Event, get_new_event_identifier\nfrom app.models import db\nfrom app.models.microlocation import Microlocation\nfrom app.models.social_link import SocialLink\nfrom app.models.speakers_call import SpeakersCall\nfrom app.models.sponsor import Sponsor\nfrom app.models.ticket import Ticket\nfrom app.models.track import Track\nfrom app.models.users_events_role import UsersEventsRoles\n\nevent_copy = Blueprint('event_copy', __name__, url_prefix='/v1/events')\n\n\n@event_copy.route('/<identifier>/copy', methods=['POST'])\ndef create_event_copy(identifier):\n    id = 'identifier'\n\n    if identifier.isdigit():\n        id = 'id'\n\n    event = safe_query(db, Event, id, identifier, 'event_' + id)\n\n    if not has_access('is_coorganizer', event_id=event.id):\n        return abort(\n            make_response(jsonify(error=\"Access Forbidden\"), 403)\n        )\n    tickets = Ticket.query.filter_by(event_id=event.id).all()\n    social_links = SocialLink.query.filter_by(event_id=event.id).all()\n    sponsors = Sponsor.query.filter_by(event_id=event.id).all()\n    microlocations = Microlocation.query.filter_by(event_id=event.id).all()\n    tracks = Track.query.filter_by(event_id=event.id).all()\n    custom_forms = CustomForms.query.filter_by(event_id=event.id).all()\n    discount_codes = DiscountCode.query.filter_by(event_id=event.id).all()\n    speaker_calls = SpeakersCall.query.filter_by(event_id=event.id).all()\n    user_event_roles = UsersEventsRoles.query.filter_by(event_id=event.id).all()\n\n    db.session.expunge(event)  # expunge the object from session\n    make_transient(event)\n    delattr(event, 'id')\n    event.identifier = get_new_event_identifier()\n    db.session.add(event)\n    db.session.commit()\n\n    # Removes access_codes, order_tickets, ticket_tags for the new tickets created.\n    for ticket in tickets:\n        ticket_id = ticket.id\n        db.session.expunge(ticket)  # expunge the object from session\n        make_transient(ticket)\n        ticket.event_id = event.id\n        delattr(ticket, 'id')\n        db.session.add(ticket)\n        db.session.commit()\n\n    for link in social_links:\n        link_id = link.id\n        db.session.expunge(link)  # expunge the object from session\n        make_transient(link)\n        link.event_id = event.id\n        delattr(link, 'id')\n        db.session.add(link)\n        db.session.commit()\n\n    for sponsor in sponsors:\n        sponsor_id = sponsor.id\n        db.session.expunge(sponsor)  # expunge the object from session\n        make_transient(sponsor)\n        sponsor.event_id = event.id\n        logo_url = create_save_resized_image(image_file=sponsor.logo_url, resize=False)\n        delattr(sponsor, 'id')\n        sponsor.logo_url = logo_url\n        db.session.add(sponsor)\n        db.session.commit()\n\n    for location in microlocations:\n        location_id = location.id\n        db.session.expunge(location)  # expunge the object from session\n        make_transient(location)\n        location.event_id = event.id\n        delattr(location, 'id')\n        db.session.add(location)\n        db.session.commit()\n\n    # No sessions are copied for new tracks\n    for track in tracks:\n        track_id = track.id\n        db.session.expunge(track)  # expunge the object from session\n        make_transient(track)\n        track.event_id = event.id\n        delattr(track, 'id')\n        db.session.add(track)\n        db.session.commit()\n\n    for call in speaker_calls:\n        call_id = call.id\n        db.session.expunge(call)  # expunge the object from session\n        make_transient(call)\n        call.event_id = event.id\n        delattr(call, 'id')\n        db.session.add(call)\n        db.session.commit()\n\n    for code in discount_codes:\n        code_id = code.id\n        db.session.expunge(code)  # expunge the object from session\n        make_transient(code)\n        code.event_id = event.id\n        delattr(code, 'id')\n        db.session.add(code)\n        db.session.commit()\n\n    for form in custom_forms:\n        form_id = form.id\n        db.session.expunge(form)  # expunge the object from session\n        make_transient(form)\n        form.event_id = event.id\n        delattr(form, 'id')\n        db.session.add(form)\n        db.session.commit()\n\n    for user_role in user_event_roles:\n        db.session.expunge(user_role)\n        make_transient(user_role)\n        user_role.event_id = event.id\n        delattr(user_role, 'id')\n        db.session.add(user_role)\n        db.session.commit()\n\n    return jsonify({\n        'id': event.id,\n        'identifier': event.identifier,\n        \"copied\": True\n    })\n", "path": "app/api/event_copy.py"}]}