# Buggy code
def to_json(self) -> "Dict[str, Union[str, int, bool]]":
    json_submission = {
        "source_url": url_for("api.single_source", source_uuid=self.source.uuid),
        "submission_url": url_for(
            "api.single_submission",
            source_uuid=self.source.uuid,
            submission_uuid=self.uuid,
        ),
        "filename": self.filename,
        "size": self.size,
        "is_read": self.downloaded,
        "uuid": self.uuid,
        "download_url": url_for(
            "api.download_submission",
            source_uuid=self.source.uuid,
            submission_uuid=self.uuid,
        ),
    }
    return json_submission


# Traceback (AttributeError)
Traceback (most recent call last):
File "/opt/venvs/securedrop-app-code/lib/python3.5/site-packages/flask/app.py", line 2309, in __call__
return self.wsgi_app(environ, start_response)
File "/opt/venvs/securedrop-app-code/lib/python3.5/site-packages/flask/app.py", line 2295, in wsgi_app
response = self.handle_exception(e)
File "/opt/venvs/securedrop-app-code/lib/python3.5/site-packages/flask/app.py", line 1741, in handle_exception
reraise(exc_type, exc_value, tb)
File "/opt/venvs/securedrop-app-code/lib/python3.5/site-packages/flask/_compat.py", line 35, in reraise
raise value
File "/opt/venvs/securedrop-app-code/lib/python3.5/site-packages/flask/app.py", line 2292, in wsgi_app
response = self.full_dispatch_request()
File "/opt/venvs/securedrop-app-code/lib/python3.5/site-packages/flask/app.py", line 1815, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/opt/venvs/securedrop-app-code/lib/python3.5/site-packages/flask/app.py", line 1718, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/opt/venvs/securedrop-app-code/lib/python3.5/site-packages/flask/_compat.py", line 35, in reraise
raise value
File "/opt/venvs/securedrop-app-code/lib/python3.5/site-packages/flask/app.py", line 1813, in full_dispatch_request
rv = self.dispatch_request()
File "/opt/venvs/securedrop-app-code/lib/python3.5/site-packages/flask/app.py", line 1799, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/Users/redshiftzero/Documents/Github/securedrop-1.2.0-rc1/securedrop/securedrop/journalist_app/api.py", line 48, in decorated_function
return f(*args, **kwargs)
File "/Users/redshiftzero/Documents/Github/securedrop-1.2.0-rc1/securedrop/securedrop/journalist_app/api.py", line 303, in get_all_submissions
submission in submissions]}), 200
File "/Users/redshiftzero/Documents/Github/securedrop-1.2.0-rc1/securedrop/securedrop/journalist_app/api.py", line 303, in <listcomp>
submission in submissions]}), 200
File "/Users/redshiftzero/Documents/Github/securedrop-1.2.0-rc1/securedrop/securedrop/models.py", line 218, in to_json
source_uuid=self.source.uuid),
AttributeError: 'NoneType' object has no attribute 'uuid'

# Fixed code
def to_json(self) -> "Dict[str, Union[str, int, bool]]":
    json_submission = {
        "source_url": url_for("api.single_source", source_uuid=self.source.uuid)
        if self.source
        else None,
        "submission_url": url_for(
            "api.single_submission",
            source_uuid=self.source.uuid,
            submission_uuid=self.uuid,
        )
        if self.source
        else None,
        "filename": self.filename,
        "size": self.size,
        "is_read": self.downloaded,
        "uuid": self.uuid,
        "download_url": url_for(
            "api.download_submission",
            source_uuid=self.source.uuid,
            submission_uuid=self.uuid,
        )
        if self.source
        else None,
    }
    return json_submission