Repository: fossasia/open-event-server

Issue:
Adding an event image while creating event leads to a timeout
**Describe the bug**
<!-- A clear and concise description of what the bug is. -->
On event creation wizard step 1, if an event image is added which corresponds to the `original-image-url` attribute of event model inside the server, the POST or PATCH request times out, and server doesn't generate any logs.

If this block of code is removed from `api/events.py`, the issue gets fixed, which means it has something to do with these helper functions.

```python
        if data.get('original_image_url') and data['original_image_url'] != event.original_image_url:
            try:
                uploaded_images = create_save_image_sizes(data['original_image_url'], 'event-image', event.id)
            except (urllib.error.HTTPError, urllib.error.URLError):
                raise UnprocessableEntity(
                    {'source': 'attributes/original-image-url'}, 'Invalid Image URL'
                )
            data['original_image_url'] = uploaded_images['original_image_url']
            data['large_image_url'] = uploaded_images['large_image_url']
            data['thumbnail_image_url'] = uploaded_images['thumbnail_image_url']
            data['icon_image_url'] = uploaded_images['icon_image_url']
```




Discussion:
There is a need to create a asynchronous celery task concerning this block.
@bhaveshAn If you are willing to do it, it sounds good, please let me know ASAP, else I will be removing it for now, as it's a direct blocker to creating an event.

Resolving patch:
diff --git a/app/api/events.py b/app/api/events.py
--- a/app/api/events.py
+++ b/app/api/events.py
@@ -173,16 +173,16 @@ def after_create_object(self, event, data, view_kwargs):
 
         if event.state == 'published' and event.schedule_published_on:
             start_export_tasks(event)
-
-        if data.get('original_image_url'):
-            try:
-                uploaded_images = create_save_image_sizes(data['original_image_url'], 'event-image', event.id)
-            except (urllib.error.HTTPError, urllib.error.URLError):
-                raise UnprocessableEntity(
-                    {'source': 'attributes/original-image-url'}, 'Invalid Image URL'
-                )
-            self.session.query(Event).filter_by(id=event.id).update(uploaded_images)
-            self.session.commit()
+        # TODO: Create an asynchronous celery task for this
+        # if data.get('original_image_url'):
+        #     try:
+        #         uploaded_images = create_save_image_sizes(data['original_image_url'], 'event-image', event.id)
+        #     except (urllib.error.HTTPError, urllib.error.URLError):
+        #         raise UnprocessableEntity(
+        #             {'source': 'attributes/original-image-url'}, 'Invalid Image URL'
+        #         )
+        #     self.session.query(Event).filter_by(id=event.id).update(uploaded_images)
+        #     self.session.commit()
 
     # This permission decorator ensures, you are logged in to create an event
     # and have filter ?withRole to get events associated with logged in user
@@ -500,17 +500,18 @@ def before_update_object(self, event, data, view_kwargs):
         :param view_kwargs:
         :return:
         """
-        if data.get('original_image_url') and data['original_image_url'] != event.original_image_url:
-            try:
-                uploaded_images = create_save_image_sizes(data['original_image_url'], 'event-image', event.id)
-            except (urllib.error.HTTPError, urllib.error.URLError):
-                raise UnprocessableEntity(
-                    {'source': 'attributes/original-image-url'}, 'Invalid Image URL'
-                )
-            data['original_image_url'] = uploaded_images['original_image_url']
-            data['large_image_url'] = uploaded_images['large_image_url']
-            data['thumbnail_image_url'] = uploaded_images['thumbnail_image_url']
-            data['icon_image_url'] = uploaded_images['icon_image_url']
+        # TODO: Create an asynchronous celery task for this
+        # if data.get('original_image_url') and data['original_image_url'] != event.original_image_url:
+        #     try:
+        #         uploaded_images = create_save_image_sizes(data['original_image_url'], 'event-image', event.id)
+        #     except (urllib.error.HTTPError, urllib.error.URLError):
+        #         raise UnprocessableEntity(
+        #             {'source': 'attributes/original-image-url'}, 'Invalid Image URL'
+        #         )
+        #     data['original_image_url'] = uploaded_images['original_image_url']
+        #     data['large_image_url'] = uploaded_images['large_image_url']
+        #     data['thumbnail_image_url'] = uploaded_images['thumbnail_image_url']
+        #     data['icon_image_url'] = uploaded_images['icon_image_url']
 
         if has_access('is_admin') and data.get('deleted_at') != event.deleted_at:
             event.deleted_at = data.get('deleted_at')


Test patch: