We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Method to insert session-speaker relationship missing
**I'm submitting a ...**  (check one with "x")
- [x] bug report
- [ ] feature request
- [ ] support request => Please do not submit support requests here, instead ask your query in out Gitter channel at https://gitter.im/fossasia/open-event-orga-server

**Current behavior:**
<!-- Describe how the bug manifests. -->

**Expected behavior:**
Session must be updated with related speakers and data inserted in speakers-session table. 

**Steps to reproduce:**
<!-- If you are able to illustrate the bug or feature request with an example, please provide steps to reproduce -->

**Related code:**

```
insert any relevant code here else remove this section
```

**Other information:**
<!-- List any other information that is relevant to your issue. Stack traces, related issues, suggestions on how to fix, Stack Overflow links, forum links, etc. -->

**System information:** 




--- 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/speakers.py`
Content:
```
1 from marshmallow_jsonapi import fields
2 from marshmallow_jsonapi.flask import Schema, Relationship
3 from flask_rest_jsonapi import ResourceDetail, ResourceList, ResourceRelationship
4 
5 from app.api.helpers.utilities import dasherize
6 from app.api.helpers.permissions import jwt_required, current_identity
7 from app.models import db
8 from app.models.speaker import Speaker
9 from app.models.session import Session
10 from app.models.user import User
11 from app.models.event import Event
12 from app.api.helpers.db import safe_query
13 from app.api.bootstrap import api
14 
15 
16 class SpeakerSchema(Schema):
17     """
18     Speaker Schema based on Speaker Model
19     """
20     class Meta:
21         """
22         Meta class for speaker schema
23         """
24         type_ = 'speaker'
25         self_view = 'v1.speaker_detail'
26         self_view_kwargs = {'id': '<id>'}
27         inflect = dasherize
28 
29     id = fields.Str(dump_only=True)
30     name = fields.Str(required=True)
31     email = fields.Str(required=True)
32     photo_url = fields.Url(allow_none=True)
33     thumbnail_image_url = fields.Url(allow_none=True)
34     small_image_url = fields.Url(allow_none=True)
35     icon_image_url = fields.Url(allow_none=True)
36     short_biography = fields.Str(allow_none=True)
37     long_biography = fields.Str(allow_none=True)
38     speaking_experience = fields.Str(allow_none=True)
39     mobile = fields.Str(allow_none=True)
40     website = fields.Url(allow_none=True)
41     twitter = fields.Url(allow_none=True)
42     facebook = fields.Url(allow_none=True)
43     github = fields.Url(allow_none=True)
44     linkedin = fields.Url(allow_none=True)
45     organisation = fields.Str(allow_none=True)
46     is_featured = fields.Boolean(default=False)
47     position = fields.Str(allow_none=True)
48     country = fields.Str(allow_none=True)
49     city = fields.Str(allow_none=True)
50     gender = fields.Str(allow_none=True)
51     heard_from = fields.Str(allow_none=True)
52     sponsorship_required = fields.Str(allow_none=True)
53     event = Relationship(attribute='event',
54                          self_view='v1.speaker_event',
55                          self_view_kwargs={'id': '<id>'},
56                          related_view='v1.event_detail',
57                          related_view_kwargs={'speaker_id': '<id>'},
58                          schema='EventSchema',
59                          type_='event')
60     user = Relationship(attribute='user',
61                         self_view='v1.speaker_user',
62                         self_view_kwargs={'id': '<id>'},
63                         related_view='v1.user_detail',
64                         related_view_kwargs={'speaker_id': '<id>'},
65                         schema='UserSchema',
66                         type_='user')
67     sessions = Relationship(attribute='sessions',
68                             self_view='v1.speaker_session',
69                             self_view_kwargs={'id': '<id>'},
70                             related_view='v1.session_list',
71                             related_view_kwargs={'speaker_id': '<id>'},
72                             schema='SessionSchema',
73                             type_='session')
74 
75 
76 class SpeakerList(ResourceList):
77     """
78     List and create speakers
79     """
80     def query(self, view_kwargs):
81         """
82         query method for speakers list class
83         :param view_kwargs:
84         :return:
85         """
86         query_ = self.session.query(Speaker)
87         if view_kwargs.get('event_id'):
88             event = safe_query(self, Event, 'id', view_kwargs['event_id'], 'event_id')
89             query_ = query_.join(Event).filter(Event.id == event.id)
90         elif view_kwargs.get('event_identifier'):
91             event = safe_query(self, Event, 'identifier', view_kwargs['event_identifier'], 'event_identifier')
92             query_ = query_.join(Event).filter(Event.id == event.id)
93         if view_kwargs.get('user_id'):
94             user = safe_query(self, User, 'id', view_kwargs['user_id'], 'user_id')
95             query_ = query_.join(User).filter(User.id == user.id)
96         if view_kwargs.get('session_id'):
97             session = safe_query(self, Session, 'id', view_kwargs['session_id'], 'session_id')
98             # session-speaker :: many-to-many relationship
99             query_ = Speaker.query.filter(Speaker.sessions.any(id=session.id))
100         return query_
101 
102     def before_post(self, args, kwargs, data):
103         """
104         method to add user_id to view_kwargs before post
105         :param args:
106         :param kwargs:
107         :param data:
108         :return:
109         """
110         kwargs['user_id'] = current_identity.id
111 
112     def before_create_object(self, data, view_kwargs):
113         """
114         before create object method for speaker list class
115         :param data:
116         :param view_kwargs:
117         :return:
118         """
119         if view_kwargs.get('event_id'):
120             event = safe_query(self, Event, 'id', view_kwargs['event_id'], 'event_id')
121             data['event_id'] = event.id
122         elif view_kwargs.get('event_identifier'):
123             event = safe_query(self, Event, 'identifier', view_kwargs['event_identifier'], 'event_identifier')
124             data['event_id'] = event.id
125         data['user_id'] = current_identity.id
126 
127     view_kwargs = True
128     decorators = (api.has_permission('accessible_role_based_events'),)
129     schema = SpeakerSchema
130     data_layer = {'session': db.session,
131                   'model': Speaker,
132                   'methods': {
133                       'query': query,
134                       'before_create_object': before_create_object,
135                       'before_post': before_post
136                   }}
137 
138 
139 class SpeakerDetail(ResourceDetail):
140     """
141     Speakers Detail by id
142     """
143     decorators = (api.has_permission('is_coorganizer_or_user_itself', methods="PATCH,DELETE", fetch="event_id",
144                                      fetch_as="event_id", model=Speaker, check=lambda a: a.get('id') is not None),)
145     schema = SpeakerSchema
146     data_layer = {'session': db.session,
147                   'model': Speaker}
148 
149 
150 class SpeakerRelationship(ResourceRelationship):
151     """
152     Speaker Relationship class
153     """
154     decorators = (jwt_required,)
155     schema = SpeakerSchema
156     data_layer = {'session': db.session,
157                   'model': Speaker}
158
```
--- 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()

```

diff --git a/app/api/speakers.py b/app/api/speakers.py
--- a/app/api/speakers.py
+++ b/app/api/speakers.py
@@ -116,6 +116,9 @@
         :param view_kwargs:
         :return:
         """
+        if view_kwargs.get('session_id'):
+            session = safe_query(self, Session, 'id', view_kwargs['session_id'], 'session_id')
+            data['event_id'] = session.event_id
         if view_kwargs.get('event_id'):
             event = safe_query(self, Event, 'id', view_kwargs['event_id'], 'event_id')
             data['event_id'] = event.id
@@ -124,6 +127,12 @@
             data['event_id'] = event.id
         data['user_id'] = current_identity.id
 
+    def after_create_object(self, obj, data, view_kwargs):
+        if view_kwargs.get('session_id'):
+            session = safe_query(self, Session, 'id', view_kwargs['session_id'], 'session_id')
+            session.speakers.append(obj)
+            self.session.commit()
+
     view_kwargs = True
     decorators = (api.has_permission('accessible_role_based_events'),)
     schema = SpeakerSchema
@@ -132,7 +141,8 @@
                   'methods': {
                       'query': query,
                       'before_create_object': before_create_object,
-                      'before_post': before_post
+                      'before_post': before_post,
+                      'after_create_object': after_create_object
                   }}

{"golden_diff": "diff --git a/app/api/speakers.py b/app/api/speakers.py\n--- a/app/api/speakers.py\n+++ b/app/api/speakers.py\n@@ -116,6 +116,9 @@\n         :param view_kwargs:\n         :return:\n         \"\"\"\n+        if view_kwargs.get('session_id'):\n+            session = safe_query(self, Session, 'id', view_kwargs['session_id'], 'session_id')\n+            data['event_id'] = session.event_id\n         if view_kwargs.get('event_id'):\n             event = safe_query(self, Event, 'id', view_kwargs['event_id'], 'event_id')\n             data['event_id'] = event.id\n@@ -124,6 +127,12 @@\n             data['event_id'] = event.id\n         data['user_id'] = current_identity.id\n \n+    def after_create_object(self, obj, data, view_kwargs):\n+        if view_kwargs.get('session_id'):\n+            session = safe_query(self, Session, 'id', view_kwargs['session_id'], 'session_id')\n+            session.speakers.append(obj)\n+            self.session.commit()\n+\n     view_kwargs = True\n     decorators = (api.has_permission('accessible_role_based_events'),)\n     schema = SpeakerSchema\n@@ -132,7 +141,8 @@\n                   'methods': {\n                       'query': query,\n                       'before_create_object': before_create_object,\n-                      'before_post': before_post\n+                      'before_post': before_post,\n+                      'after_create_object': after_create_object\n                   }}\n", "issue": "Method to insert session-speaker relationship missing\n**I'm submitting a ...**  (check one with \"x\")\r\n- [x] bug report\r\n- [ ] feature request\r\n- [ ] support request => Please do not submit support requests here, instead ask your query in out Gitter channel at https://gitter.im/fossasia/open-event-orga-server\r\n\r\n**Current behavior:**\r\n<!-- Describe how the bug manifests. -->\r\n\r\n**Expected behavior:**\r\nSession must be updated with related speakers and data inserted in speakers-session table. \r\n\r\n**Steps to reproduce:**\r\n<!-- If you are able to illustrate the bug or feature request with an example, please provide steps to reproduce -->\r\n\r\n**Related code:**\r\n\r\n```\r\ninsert any relevant code here else remove this section\r\n```\r\n\r\n**Other information:**\r\n<!-- List any other information that is relevant to your issue. Stack traces, related issues, suggestions on how to fix, Stack Overflow links, forum links, etc. -->\r\n\r\n**System information:** \r\n\r\n\r\n\n", "before_files": [{"content": "from marshmallow_jsonapi import fields\nfrom marshmallow_jsonapi.flask import Schema, Relationship\nfrom flask_rest_jsonapi import ResourceDetail, ResourceList, ResourceRelationship\n\nfrom app.api.helpers.utilities import dasherize\nfrom app.api.helpers.permissions import jwt_required, current_identity\nfrom app.models import db\nfrom app.models.speaker import Speaker\nfrom app.models.session import Session\nfrom app.models.user import User\nfrom app.models.event import Event\nfrom app.api.helpers.db import safe_query\nfrom app.api.bootstrap import api\n\n\nclass SpeakerSchema(Schema):\n    \"\"\"\n    Speaker Schema based on Speaker Model\n    \"\"\"\n    class Meta:\n        \"\"\"\n        Meta class for speaker schema\n        \"\"\"\n        type_ = 'speaker'\n        self_view = 'v1.speaker_detail'\n        self_view_kwargs = {'id': '<id>'}\n        inflect = dasherize\n\n    id = fields.Str(dump_only=True)\n    name = fields.Str(required=True)\n    email = fields.Str(required=True)\n    photo_url = fields.Url(allow_none=True)\n    thumbnail_image_url = fields.Url(allow_none=True)\n    small_image_url = fields.Url(allow_none=True)\n    icon_image_url = fields.Url(allow_none=True)\n    short_biography = fields.Str(allow_none=True)\n    long_biography = fields.Str(allow_none=True)\n    speaking_experience = fields.Str(allow_none=True)\n    mobile = fields.Str(allow_none=True)\n    website = fields.Url(allow_none=True)\n    twitter = fields.Url(allow_none=True)\n    facebook = fields.Url(allow_none=True)\n    github = fields.Url(allow_none=True)\n    linkedin = fields.Url(allow_none=True)\n    organisation = fields.Str(allow_none=True)\n    is_featured = fields.Boolean(default=False)\n    position = fields.Str(allow_none=True)\n    country = fields.Str(allow_none=True)\n    city = fields.Str(allow_none=True)\n    gender = fields.Str(allow_none=True)\n    heard_from = fields.Str(allow_none=True)\n    sponsorship_required = fields.Str(allow_none=True)\n    event = Relationship(attribute='event',\n                         self_view='v1.speaker_event',\n                         self_view_kwargs={'id': '<id>'},\n                         related_view='v1.event_detail',\n                         related_view_kwargs={'speaker_id': '<id>'},\n                         schema='EventSchema',\n                         type_='event')\n    user = Relationship(attribute='user',\n                        self_view='v1.speaker_user',\n                        self_view_kwargs={'id': '<id>'},\n                        related_view='v1.user_detail',\n                        related_view_kwargs={'speaker_id': '<id>'},\n                        schema='UserSchema',\n                        type_='user')\n    sessions = Relationship(attribute='sessions',\n                            self_view='v1.speaker_session',\n                            self_view_kwargs={'id': '<id>'},\n                            related_view='v1.session_list',\n                            related_view_kwargs={'speaker_id': '<id>'},\n                            schema='SessionSchema',\n                            type_='session')\n\n\nclass SpeakerList(ResourceList):\n    \"\"\"\n    List and create speakers\n    \"\"\"\n    def query(self, view_kwargs):\n        \"\"\"\n        query method for speakers list class\n        :param view_kwargs:\n        :return:\n        \"\"\"\n        query_ = self.session.query(Speaker)\n        if view_kwargs.get('event_id'):\n            event = safe_query(self, Event, 'id', view_kwargs['event_id'], 'event_id')\n            query_ = query_.join(Event).filter(Event.id == event.id)\n        elif view_kwargs.get('event_identifier'):\n            event = safe_query(self, Event, 'identifier', view_kwargs['event_identifier'], 'event_identifier')\n            query_ = query_.join(Event).filter(Event.id == event.id)\n        if view_kwargs.get('user_id'):\n            user = safe_query(self, User, 'id', view_kwargs['user_id'], 'user_id')\n            query_ = query_.join(User).filter(User.id == user.id)\n        if view_kwargs.get('session_id'):\n            session = safe_query(self, Session, 'id', view_kwargs['session_id'], 'session_id')\n            # session-speaker :: many-to-many relationship\n            query_ = Speaker.query.filter(Speaker.sessions.any(id=session.id))\n        return query_\n\n    def before_post(self, args, kwargs, data):\n        \"\"\"\n        method to add user_id to view_kwargs before post\n        :param args:\n        :param kwargs:\n        :param data:\n        :return:\n        \"\"\"\n        kwargs['user_id'] = current_identity.id\n\n    def before_create_object(self, data, view_kwargs):\n        \"\"\"\n        before create object method for speaker list class\n        :param data:\n        :param view_kwargs:\n        :return:\n        \"\"\"\n        if view_kwargs.get('event_id'):\n            event = safe_query(self, Event, 'id', view_kwargs['event_id'], 'event_id')\n            data['event_id'] = event.id\n        elif view_kwargs.get('event_identifier'):\n            event = safe_query(self, Event, 'identifier', view_kwargs['event_identifier'], 'event_identifier')\n            data['event_id'] = event.id\n        data['user_id'] = current_identity.id\n\n    view_kwargs = True\n    decorators = (api.has_permission('accessible_role_based_events'),)\n    schema = SpeakerSchema\n    data_layer = {'session': db.session,\n                  'model': Speaker,\n                  'methods': {\n                      'query': query,\n                      'before_create_object': before_create_object,\n                      'before_post': before_post\n                  }}\n\n\nclass SpeakerDetail(ResourceDetail):\n    \"\"\"\n    Speakers Detail by id\n    \"\"\"\n    decorators = (api.has_permission('is_coorganizer_or_user_itself', methods=\"PATCH,DELETE\", fetch=\"event_id\",\n                                     fetch_as=\"event_id\", model=Speaker, check=lambda a: a.get('id') is not None),)\n    schema = SpeakerSchema\n    data_layer = {'session': db.session,\n                  'model': Speaker}\n\n\nclass SpeakerRelationship(ResourceRelationship):\n    \"\"\"\n    Speaker Relationship class\n    \"\"\"\n    decorators = (jwt_required,)\n    schema = SpeakerSchema\n    data_layer = {'session': db.session,\n                  'model': Speaker}\n", "path": "app/api/speakers.py"}], "after_files": [{"content": "from marshmallow_jsonapi import fields\nfrom marshmallow_jsonapi.flask import Schema, Relationship\nfrom flask_rest_jsonapi import ResourceDetail, ResourceList, ResourceRelationship\n\nfrom app.api.helpers.utilities import dasherize\nfrom app.api.helpers.permissions import jwt_required, current_identity\nfrom app.models import db\nfrom app.models.speaker import Speaker\nfrom app.models.session import Session\nfrom app.models.user import User\nfrom app.models.event import Event\nfrom app.api.helpers.db import safe_query\nfrom app.api.bootstrap import api\n\n\nclass SpeakerSchema(Schema):\n    \"\"\"\n    Speaker Schema based on Speaker Model\n    \"\"\"\n    class Meta:\n        \"\"\"\n        Meta class for speaker schema\n        \"\"\"\n        type_ = 'speaker'\n        self_view = 'v1.speaker_detail'\n        self_view_kwargs = {'id': '<id>'}\n        inflect = dasherize\n\n    id = fields.Str(dump_only=True)\n    name = fields.Str(required=True)\n    email = fields.Str(required=True)\n    photo_url = fields.Url(allow_none=True)\n    thumbnail_image_url = fields.Url(allow_none=True)\n    small_image_url = fields.Url(allow_none=True)\n    icon_image_url = fields.Url(allow_none=True)\n    short_biography = fields.Str(allow_none=True)\n    long_biography = fields.Str(allow_none=True)\n    speaking_experience = fields.Str(allow_none=True)\n    mobile = fields.Str(allow_none=True)\n    website = fields.Url(allow_none=True)\n    twitter = fields.Url(allow_none=True)\n    facebook = fields.Url(allow_none=True)\n    github = fields.Url(allow_none=True)\n    linkedin = fields.Url(allow_none=True)\n    organisation = fields.Str(allow_none=True)\n    is_featured = fields.Boolean(default=False)\n    position = fields.Str(allow_none=True)\n    country = fields.Str(allow_none=True)\n    city = fields.Str(allow_none=True)\n    gender = fields.Str(allow_none=True)\n    heard_from = fields.Str(allow_none=True)\n    sponsorship_required = fields.Str(allow_none=True)\n    event = Relationship(attribute='event',\n                         self_view='v1.speaker_event',\n                         self_view_kwargs={'id': '<id>'},\n                         related_view='v1.event_detail',\n                         related_view_kwargs={'speaker_id': '<id>'},\n                         schema='EventSchema',\n                         type_='event')\n    user = Relationship(attribute='user',\n                        self_view='v1.speaker_user',\n                        self_view_kwargs={'id': '<id>'},\n                        related_view='v1.user_detail',\n                        related_view_kwargs={'speaker_id': '<id>'},\n                        schema='UserSchema',\n                        type_='user')\n    sessions = Relationship(attribute='sessions',\n                            self_view='v1.speaker_session',\n                            self_view_kwargs={'id': '<id>'},\n                            related_view='v1.session_list',\n                            related_view_kwargs={'speaker_id': '<id>'},\n                            schema='SessionSchema',\n                            type_='session')\n\n\nclass SpeakerList(ResourceList):\n    \"\"\"\n    List and create speakers\n    \"\"\"\n    def query(self, view_kwargs):\n        \"\"\"\n        query method for speakers list class\n        :param view_kwargs:\n        :return:\n        \"\"\"\n        query_ = self.session.query(Speaker)\n        if view_kwargs.get('event_id'):\n            event = safe_query(self, Event, 'id', view_kwargs['event_id'], 'event_id')\n            query_ = query_.join(Event).filter(Event.id == event.id)\n        elif view_kwargs.get('event_identifier'):\n            event = safe_query(self, Event, 'identifier', view_kwargs['event_identifier'], 'event_identifier')\n            query_ = query_.join(Event).filter(Event.id == event.id)\n        if view_kwargs.get('user_id'):\n            user = safe_query(self, User, 'id', view_kwargs['user_id'], 'user_id')\n            query_ = query_.join(User).filter(User.id == user.id)\n        if view_kwargs.get('session_id'):\n            session = safe_query(self, Session, 'id', view_kwargs['session_id'], 'session_id')\n            # session-speaker :: many-to-many relationship\n            query_ = Speaker.query.filter(Speaker.sessions.any(id=session.id))\n        return query_\n\n    def before_post(self, args, kwargs, data):\n        \"\"\"\n        method to add user_id to view_kwargs before post\n        :param args:\n        :param kwargs:\n        :param data:\n        :return:\n        \"\"\"\n        kwargs['user_id'] = current_identity.id\n\n    def before_create_object(self, data, view_kwargs):\n        \"\"\"\n        before create object method for speaker list class\n        :param data:\n        :param view_kwargs:\n        :return:\n        \"\"\"\n        if view_kwargs.get('session_id'):\n            session = safe_query(self, Session, 'id', view_kwargs['session_id'], 'session_id')\n            data['event_id'] = session.event_id\n        if view_kwargs.get('event_id'):\n            event = safe_query(self, Event, 'id', view_kwargs['event_id'], 'event_id')\n            data['event_id'] = event.id\n        elif view_kwargs.get('event_identifier'):\n            event = safe_query(self, Event, 'identifier', view_kwargs['event_identifier'], 'event_identifier')\n            data['event_id'] = event.id\n        data['user_id'] = current_identity.id\n\n    def after_create_object(self, obj, data, view_kwargs):\n        if view_kwargs.get('session_id'):\n            session = safe_query(self, Session, 'id', view_kwargs['session_id'], 'session_id')\n            session.speakers.append(obj)\n            self.session.commit()\n\n    view_kwargs = True\n    decorators = (api.has_permission('accessible_role_based_events'),)\n    schema = SpeakerSchema\n    data_layer = {'session': db.session,\n                  'model': Speaker,\n                  'methods': {\n                      'query': query,\n                      'before_create_object': before_create_object,\n                      'before_post': before_post,\n                      'after_create_object': after_create_object\n                  }}\n\n\nclass SpeakerDetail(ResourceDetail):\n    \"\"\"\n    Speakers Detail by id\n    \"\"\"\n    decorators = (api.has_permission('is_coorganizer_or_user_itself', methods=\"PATCH,DELETE\", fetch=\"event_id\",\n                                     fetch_as=\"event_id\", model=Speaker, check=lambda a: a.get('id') is not None),)\n    schema = SpeakerSchema\n    data_layer = {'session': db.session,\n                  'model': Speaker}\n\n\nclass SpeakerRelationship(ResourceRelationship):\n    \"\"\"\n    Speaker Relationship class\n    \"\"\"\n    decorators = (jwt_required,)\n    schema = SpeakerSchema\n    data_layer = {'session': db.session,\n                  'model': Speaker}\n", "path": "app/api/speakers.py"}]}