Skip to content

Commit

Permalink
hotfix: CSV Export Error (#6482)
Browse files Browse the repository at this point in the history
hotfix: CSV Export Error
  • Loading branch information
iamareebjamal authored Oct 1, 2019
2 parents 43ac5c6 + f8cdfdd commit 5168992
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 28 deletions.
11 changes: 8 additions & 3 deletions app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
import sys
from flask import Flask, json, make_response
from flask_celeryext import FlaskCeleryExt
import sentry_sdk
from sentry_sdk.integrations.flask import FlaskIntegration
from sentry_sdk.integrations.celery import CeleryIntegration
from sentry_sdk.integrations.redis import RedisIntegration
from sentry_sdk.integrations.sqlalchemy import SqlalchemyIntegration

from app.settings import get_settings, get_setts
from flask_migrate import Migrate, MigrateCommand
from flask_script import Manager
Expand Down Expand Up @@ -42,8 +48,6 @@
from app.views.redis_store import redis_store
from app.views.celery_ import celery
from app.templates.flask_ext.jinja.filters import init_filters
import sentry_sdk
from sentry_sdk.integrations.flask import FlaskIntegration


BASE_DIR = os.path.dirname(os.path.abspath(__file__))
Expand Down Expand Up @@ -173,7 +177,8 @@ def create_app():

# sentry
if not app_created and 'SENTRY_DSN' in app.config:
sentry_sdk.init(app.config['SENTRY_DSN'], integrations=[FlaskIntegration()])
sentry_sdk.init(app.config['SENTRY_DSN'], integrations=[FlaskIntegration(), RedisIntegration(),
CeleryIntegration(), SqlalchemyIntegration()])

# redis
redis_store.init_app(app)
Expand Down
2 changes: 1 addition & 1 deletion app/api/helpers/csv_jobs_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def export_sessions_csv(sessions):
column.append(session.level)
column.append(session.state)
column.append(session.session_type if session.session_type else '')
column.append(len(session.long_abstract))
column.append(len(session.long_abstract) if session.long_abstract else None)
rows.append(column)

return rows
Expand Down
5 changes: 1 addition & 4 deletions app/api/helpers/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ def save_to_db(item, msg="Saved to db", print_error=True):
db.session.commit()
return True
except Exception as e:
if print_error:
print(e)
traceback.print_exc()
logging.error('DB Exception! %s' % e)
logging.exception('DB Exception!')
db.session.rollback()
return False

Expand Down
4 changes: 2 additions & 2 deletions app/api/helpers/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def delete_related_attendees_for_order(order):
try:
db.session.commit()
except Exception as e:
logging.error('DB Exception! %s' % e)
logging.exception('DB Exception!')
db.session.rollback()


Expand Down Expand Up @@ -114,7 +114,7 @@ def create_onsite_attendees_for_order(data):
try:
db.session.commit()
except Exception as e:
logging.error('DB Exception! %s' % e)
logging.exception('DB Exception!')
db.session.rollback()

raise ConflictException(
Expand Down
25 changes: 13 additions & 12 deletions app/api/helpers/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import urllib.error
import base64

logger = logging.getLogger(__name__)
celery = make_celery()


Expand Down Expand Up @@ -269,7 +270,7 @@ def export_ical_task(self, event_id, temp=True):

except Exception as e:
result = {'__error': True, 'result': str(e)}
logging.error('Error in ical download')
logger.exception('Error in ical download')

return result

Expand Down Expand Up @@ -304,7 +305,7 @@ def export_xcal_task(self, event_id, temp=True):

except Exception as e:
result = {'__error': True, 'result': str(e)}
logging.error('Error in xcal download')
logger.exception('Error in xcal download')

return result

Expand Down Expand Up @@ -339,7 +340,7 @@ def export_pentabarf_task(self, event_id, temp=True):

except Exception as e:
result = {'__error': True, 'result': str(e)}
logging.error('Error in pentabarf download')
logger.exception('Error in pentabarf download')

return result

Expand Down Expand Up @@ -369,7 +370,7 @@ def export_order_csv_task(self, event_id):
}
except Exception as e:
result = {'__error': True, 'result': str(e)}
logging.error('Error in exporting as CSV')
logger.exception('Error in exporting as CSV')

return result

Expand All @@ -389,7 +390,7 @@ def export_order_pdf_task(self, event_id):
}
except Exception as e:
result = {'__error': True, 'result': str(e)}
logging.error('Error in exporting order as pdf')
logger.exception('Error in exporting order as pdf')

return result

Expand Down Expand Up @@ -418,7 +419,7 @@ def export_attendees_csv_task(self, event_id):
}
except Exception as e:
result = {'__error': True, 'result': str(e)}
logging.error('Error in exporting attendees list as CSV')
logger.exception('Error in exporting attendees list as CSV')


return result
Expand All @@ -436,7 +437,7 @@ def export_attendees_pdf_task(self, event_id):
}
except Exception as e:
result = {'__error': True, 'result': str(e)}
logging.error('Error in exporting attendees list as PDF')
logger.exception('Error in exporting attendees list as PDF')



Expand Down Expand Up @@ -467,7 +468,7 @@ def export_sessions_csv_task(self, event_id):
}
except Exception as e:
result = {'__error': True, 'result': str(e)}
logging.error('Error in exporting sessions as CSV')
logging.exception('Error in exporting sessions as CSV')

return result

Expand Down Expand Up @@ -496,7 +497,7 @@ def export_speakers_csv_task(self, event_id):
}
except Exception as e:
result = {'__error': True, 'result': str(e)}
logging.error('Error in exporting speakers list as CSV')
logger.exception('Error in exporting speakers list as CSV')

return result

Expand All @@ -513,7 +514,7 @@ def export_sessions_pdf_task(self, event_id):
}
except Exception as e:
result = {'__error': True, 'result': str(e)}
logging.error('Error in exporting sessions as PDF')
logger.exception('Error in exporting sessions as PDF')

return result

Expand All @@ -530,7 +531,7 @@ def export_speakers_pdf_task(self, event_id):
}
except Exception as e:
result = {'__error': True, 'result': str(e)}
logging.error('Error in exporting speakers as PDF')
logger.exception('Error in exporting speakers as PDF')

return result

Expand All @@ -540,4 +541,4 @@ def delete_translations(self, zip_file_path):
try:
os.remove(zip_file_path)
except:
logging.exception('Error while deleting translations zip file')
logger.exception('Error while deleting translations zip file')
5 changes: 2 additions & 3 deletions app/api/orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,12 +614,11 @@ def omise_checkout(order_identifier):
save_to_db(order)
try:
charge = OmisePaymentsManager.charge_payment(order_identifier, token)
print(charge.status)
except omise.errors.BaseError as e:
logging.error(f"""OmiseError: {repr(e)}. See https://www.omise.co/api-errors""")
logging.exception(f"""OmiseError: {repr(e)}. See https://www.omise.co/api-errors""")
return jsonify(status=False, error="Omise Failure Message: {}".format(str(e)))
except Exception as e:
logging.error(repr(e))
logging.exception('Error while charging omise')
if charge.failure_code is not None:
logging.warning("Omise Failure Message: {} ({})".format(charge.failure_message, charge.failure_code))
return jsonify(status=False, error="Omise Failure Message: {} ({})".
Expand Down
22 changes: 19 additions & 3 deletions tests/all/integration/api/helpers/test_csv_jobs_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,30 @@ def test_export_attendees_csv(self):
self.assertEqual(field_data[1][3], common.string_)
self.assertEqual(field_data[1][5], '[email protected]')

def _test_export_session_csv(self, test_session=None):
with app.test_request_context():
if not test_session:
test_session = SessionFactory()
field_data = export_sessions_csv([test_session])
session_row = field_data[1]

self.assertEqual(session_row[0], 'example (accepted)')
self.assertEqual(session_row[7], 'accepted')

def test_export_sessions_csv(self):
"""Method to check sessions data export"""

with app.test_request_context():
self._test_export_session_csv()

def test_export_sessions_none_csv(self):
"""Method to check sessions data export with no abstract"""

with app.test_request_context():
test_session = SessionFactory()
field_data = export_sessions_csv([test_session])
self.assertEqual(field_data[1][6], common.int_)
self.assertEqual(field_data[1][7], 'accepted')
test_session.long_abstract = None
test_session.level = None
self._test_export_session_csv(test_session)

def test_export_speakers_csv(self):
"""Method to check speakers data export"""
Expand Down

0 comments on commit 5168992

Please sign in to comment.