Repository: fossasia/open-event-server

Issue:
Change pdf_url to optional in create attendee api
**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-server

**Current behavior:**
Currently, the `pdf_url` attribute is shown as optional in the docs, but is required in the api call.

**Expected behavior:**
It should be optional in the api as well.

**Steps to reproduce:**
Create an attendee without `pdf_url`, eg :
```json
{
  "data": {
    "attributes": {
      "firstname": "John",
      "lastname": "Doe"
    },
    "type": "attendee",
    "relationships": {
      "event": {
        "data": {
          "id": "2",
          "type": "event"
        }
      },
      "ticket": {
        "data": {
          "id": "6",
          "type": "ticket"
        }
      }
    }
  }
}
```
Reference issue #4658 
Change pdf_url to optional in create attendee api
**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-server

**Current behavior:**
Currently, the `pdf_url` attribute is shown as optional in the docs, but is required in the api call.

**Expected behavior:**
It should be optional in the api as well.

**Steps to reproduce:**
Create an attendee without `pdf_url`, eg :
```json
{
  "data": {
    "attributes": {
      "firstname": "John",
      "lastname": "Doe"
    },
    "type": "attendee",
    "relationships": {
      "event": {
        "data": {
          "id": "2",
          "type": "event"
        }
      },
      "ticket": {
        "data": {
          "id": "6",
          "type": "ticket"
        }
      }
    }
  }
}
```
Reference issue #4658 


Discussion:
More so, it should be dump only
Yeah, it should be dump only.
More so, it should be dump only
Yeah, it should be dump only.

Resolving patch:
diff --git a/app/api/schema/attendees.py b/app/api/schema/attendees.py
--- a/app/api/schema/attendees.py
+++ b/app/api/schema/attendees.py
@@ -46,7 +46,7 @@ class Meta:
     ticket_id = fields.Str(allow_none=True)
     is_checked_in = fields.Boolean()
     checkin_times = fields.Str(allow_none=True)
-    pdf_url = fields.Url(required=True)
+    pdf_url = fields.Url(dump_only=True)
     event = Relationship(attribute='event',
                          self_view='v1.attendee_event',
                          self_view_kwargs={'id': '<id>'},
diff --git a/app/models/ticket_holder.py b/app/models/ticket_holder.py
--- a/app/models/ticket_holder.py
+++ b/app/models/ticket_holder.py
@@ -38,7 +38,7 @@ class TicketHolder(db.Model):
     github = db.Column(db.String)
     gender = db.Column(db.String)
     birth_date = db.Column(db.DateTime(timezone=True))
-    pdf_url = db.Column(db.String, nullable=False)
+    pdf_url = db.Column(db.String)
     ticket_id = db.Column(db.Integer, db.ForeignKey('tickets.id', ondelete='CASCADE'))
     order_id = db.Column(db.Integer, db.ForeignKey('orders.id', ondelete='CASCADE'))
     order = db.relationship('Order', backref='ticket_holders')
diff --git a/migrations/versions/5b9f83cede65_.py b/migrations/versions/5b9f83cede65_.py
new file mode 100644
--- /dev/null
+++ b/migrations/versions/5b9f83cede65_.py
@@ -0,0 +1,32 @@
+"""empty message
+
+Revision ID: 5b9f83cede65
+Revises: 4591885edbf0
+Create Date: 2018-04-18 17:55:43.266248
+
+"""
+
+from alembic import op
+import sqlalchemy as sa
+import sqlalchemy_utils
+
+
+# revision identifiers, used by Alembic.
+revision = '5b9f83cede65'
+down_revision = '4591885edbf0'
+
+
+def upgrade():
+    # ### commands auto generated by Alembic - please adjust! ###
+    op.alter_column('ticket_holders', 'pdf_url',
+               existing_type=sa.VARCHAR(),
+               nullable=True)
+    # ### end Alembic commands ###
+
+
+def downgrade():
+    # ### commands auto generated by Alembic - please adjust! ###
+    op.alter_column('ticket_holders', 'pdf_url',
+               existing_type=sa.VARCHAR(),
+               nullable=False)
+    # ### end Alembic commands ###


Test patch: