Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deleted journalist causes 500 on GET /replies API endpoint #5176

Closed
redshiftzero opened this issue Mar 31, 2020 · 1 comment · Fixed by #5178
Closed

deleted journalist causes 500 on GET /replies API endpoint #5176

redshiftzero opened this issue Mar 31, 2020 · 1 comment · Fixed by #5178

Comments

@redshiftzero
Copy link
Contributor

redshiftzero commented Mar 31, 2020

Description

Deleted journalist causes GET /replies endpoint to 500 if there are any replies from that deleted journalist.

Steps to Reproduce

  1. Submit a document or message as a source.
  2. Reply to the source from journalist account A.
  3. Delete the account of journalist account A (from another admin account).
  4. GET /api/v1/replies

Expected Behavior

200 OK

Actual Behavior

172.17.0.1 - - [31/Mar/2020 20:57:10] "GET /api/v1/replies HTTP/1.1" 500 -
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-rc2/securedrop/securedrop/journalist_app/api.py", line 48, in decorated_function
    return f(*args, **kwargs)
  File "/Users/redshiftzero/Documents/Github/securedrop-1.2.0-rc2/securedrop/securedrop/journalist_app/api.py", line 310, in get_all_replies
    {'replies': [reply.to_json() for reply in replies]}), 200
  File "/Users/redshiftzero/Documents/Github/securedrop-1.2.0-rc2/securedrop/securedrop/journalist_app/api.py", line 310, in <listcomp>
    {'replies': [reply.to_json() for reply in replies]}), 200
  File "/Users/redshiftzero/Documents/Github/securedrop-1.2.0-rc2/securedrop/securedrop/models.py", line 289, in to_json
    'journalist_username': self.journalist.username,
AttributeError: 'NoneType' object has no attribute 'username'

Comments

We should handle where the journalist is None here

It would be wise to also add test data to create-dev-data.py for the deleted journalist scenario (since that is used for development of securedrop-client).

@eloquence
Copy link
Member

eloquence commented Apr 1, 2020

FYI: in my testing, the SecureDrop Client will not currently handle it gracefully if the journalist-related JSON keys are missing from the API response, or if the value is NULL. If the values are empty strings, it will create an empty record in its USERS table, but apparently operate as expected.

kushaldas added a commit that referenced this issue Apr 1, 2020
We can safely return a reply by a journalist who is deleted from
the system. This patch also includes a test case, and dev-data
generation script also now adds a reply and then deletes the
journalist.
kushaldas added a commit that referenced this issue Apr 1, 2020
We can safely return a reply by a journalist who is deleted from
the system. This patch also includes a test case, and dev-data
generation script also now adds a reply and then deletes the
journalist.
kushaldas added a commit that referenced this issue Apr 1, 2020
We can safely return a reply by a journalist who is deleted from
the system. This patch also includes a test case, and dev-data
generation script also now adds a reply and then deletes the
journalist.
redshiftzero pushed a commit that referenced this issue Apr 1, 2020
We can safely return a reply by a journalist who is deleted from
the system. This patch also includes a test case, and dev-data
generation script also now adds a reply and then deletes the
journalist.
redshiftzero added a commit that referenced this issue Apr 1, 2020
Fixes #5176 Adds code+test to return replies without a journalist
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants