Repository: fossasia/open-event-server

Issue:
[Sentry]: 'EventInvoice' object has no attribute 'stripe_user_id'
https://sentry.eventyay.com/eventyay/dev-api/issues/59/

```
AttributeError: 'EventInvoice' object has no attribute 'stripe_user_id'
  File "flask/app.py", line 1982, in wsgi_app
    response = self.full_dispatch_request()
  File "flask/app.py", line 1614, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "flask_cors/extension.py", line 161, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "flask/app.py", line 1517, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "flask/app.py", line 1612, in full_dispatch_request
    rv = self.dispatch_request()
  File "flask/app.py", line 1598, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "flask_admin/base.py", line 69, in inner
    return self._run_view(f, *args, **kwargs)
  File "flask_admin/base.py", line 368, in _run_view
    return fn(self, *args, **kwargs)
  File "flask_admin/model/base.py", line 2076, in edit_view
    return_url=return_url)
  File "flask_admin/base.py", line 308, in render
    return render_template(template, **kwargs)
  File "flask/templating.py", line 134, in render_template
    context, ctx.app)
  File "flask/templating.py", line 116, in _render
    rv = template.render(context)
  File "jinja2/environment.py", line 1008, in render
    return self.environment.handle_exception(exc_info, True)
  File "jinja2/environment.py", line 780, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/app/.heroku/python/lib/python2.7/site-packages/flask_admin/templates/bootstrap3/admin/model/edit.html", line 3, in top-level template code
    {% from 'admin/lib.html' import extra with context %} {# backward compatible #}
  File "/app/.heroku/python/lib/python2.7/site-packages/flask_admin/templates/bootstrap3/admin/master.html", line 1, in top-level template code
    {% extends admin_base_template %}
  File "/app/app/templates/admin_base.html", line 1, in top-level template code
    {% extends 'admin/base.html' %}
  File "/app/.heroku/python/lib/python2.7/site-packages/flask_admin/templates/bootstrap3/admin/base.html", line 37, in top-level template code
    {% block page_body %}
  File "/app/.heroku/python/lib/python2.7/site-packages/flask_admin/templates/bootstrap3/admin/base.html", line 77, in block "page_body"
    {% block body %}{% endblock %}
  File "/app/.heroku/python/lib/python2.7/site-packages/flask_admin/templates/bootstrap3/admin/model/edit.html", line 32, in block "body"
    {% block edit_form %}
  File "/app/.heroku/python/lib/python2.7/site-packages/flask_admin/templates/bootstrap3/admin/model/edit.html", line 33, in block "edit_form"
    {{ lib.render_form(form, return_url, extra(), form_opts) }}
  File "jinja2/runtime.py", line 553, in _invoke
    rv = self._func(*arguments)
  File "/app/.heroku/python/lib/python2.7/site-packages/flask_admin/templates/bootstrap3/admin/lib.html", line 202, in template
    {% call form_tag(action=action) %}
  File "jinja2/runtime.py", line 553, in _invoke
    rv = self._func(*arguments)
  File "/app/.heroku/python/lib/python2.7/site-packages/flask_admin/templates/bootstrap3/admin/lib.html", line 182, in template
    {{ caller() }}
  File "jinja2/runtime.py", line 553, in _invoke
    rv = self._func(*arguments)
  File "/app/.heroku/python/lib/python2.7/site-packages/flask_admin/templates/bootstrap3/admin/lib.html", line 203, in template
    {{ render_form_fields(form, form_opts=form_opts) }}
  File "jinja2/runtime.py", line 553, in _invoke
    rv = self._func(*arguments)
  File "/app/.heroku/python/lib/python2.7/site-packages/flask_admin/templates/bootstrap3/admin/lib.html", line 175, in template
    {{ render_field(form, f, kwargs) }}
  File "jinja2/runtime.py", line 553, in _invoke
    rv = self._func(*arguments)
  File "/app/.heroku/python/lib/python2.7/site-packages/flask_admin/templates/bootstrap3/admin/lib.html", line 130, in template
    {{ field(**kwargs)|safe }}
  File "wtforms/fields/core.py", line 153, in __call__
    return self.meta.render_field(self, kwargs)
  File "wtforms/meta.py", line 56, in render_field
    return field.widget(field, **render_kw)
  File "flask_admin/form/widgets.py", line 28, in __call__
    return super(Select2Widget, self).__call__(field, **kwargs)
  File "wtforms/widgets/core.py", line 288, in __call__
    html.append(self.render_option(val, label, selected))
  File "wtforms/widgets/core.py", line 301, in render_option
    return HTMLString('<option %s>%s</option>' % (html_params(**options), escape(text_type(label), quote=False)))
  File "app/models/event_invoice.py", line 111, in __unicode__
    return self.stripe_user_id
```


Discussion:

Resolving patch:
diff --git a/app/models/event_invoice.py b/app/models/event_invoice.py
--- a/app/models/event_invoice.py
+++ b/app/models/event_invoice.py
@@ -102,10 +102,10 @@ def get_invoice_number(self):
         return 'I' + str(int(time.mktime(self.created_at.timetuple()))) + '-' + str(self.id)
 
     def __repr__(self):
-        return '<EventInvoice %r>' % self.stripe_user_id
+        return '<EventInvoice %r>' % self.invoice_pdf_url
 
     def __str__(self):
         return unicode(self).encode('utf-8')
 
     def __unicode__(self):
-        return self.stripe_user_id
+        return self.invoice_pdf_url


Test patch: