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

close #360 fix db warnings upon source deletion #581

Merged
merged 1 commit into from
Oct 22, 2019

Conversation

deeplow
Copy link
Contributor

@deeplow deeplow commented Oct 22, 2019

Fixes database warnings about double deletion

Description

warnings were caused by double deletion of messages

  • once upon updating the sources
  • another upon updating files, messages and replies

The bug was in update_local_storage() in the file securedrop_client/storage.py. Bellow is a copy of the buggy version.

def update_local_storage(session: Session,
                         remote_sources: List[SDKSource],
                         remote_submissions: List[SDKSubmission],
                         remote_replies: List[SDKReply],
                         data_dir: str) -> None:

    local_sources = get_local_sources(session)
    local_files = get_local_files(session)
    local_messages = get_local_messages(session)
    local_replies = get_local_replies(session)

    remote_messages = [x for x in remote_submissions if x.filename.endswith('msg.gpg')]
    remote_files = [x for x in remote_submissions if not x.filename.endswith('msg.gpg')]

    update_sources(remote_sources, local_sources, session, data_dir)
    update_files(remote_files, local_files, session, data_dir)
    update_messages(remote_messages, local_messages, session, data_dir)
    update_replies(remote_replies, local_replies, session, data_dir)

When a source was deleted all of the files, messages and replies were deleted from the db as well since they are deleted in cascade with the source according to securedrop_client/db.py.

But because local_{sources,files,messages,replies} are all fetched at once before the execution of the update_* functions they would try to delete lines in the table that were already deleted, thus the warning SAWarning: DELETE statement on table ....

Fixes #360 and possibly #545

Test Plan

  1. delete source
  2. check terminal of sd-client to see that there are no SAWarning: DELETE statement on table ... warnings

Checklist

If these changes modify code paths involving cryptography, the opening of files in VMs or network (via the RPC service) traffic, Qubes testing in the staging environment is required. For fine tuning of the graphical user interface, testing in any environment in Qubes is required. Please check as applicable:

  • I have tested these changes in the appropriate Qubes environment
  • I do not have an appropriate Qubes OS workstation set up (the reviewer will need to test these changes)
  • These changes should not need testing in Qubes

Comments

If you can make the explanation comment on the code more concise, feel free to change it.

warnings were caused by double deletion of messages
  - once upon updating the sources
  - another upon updating files, messages and replies
Copy link
Contributor

@redshiftzero redshiftzero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, thanks for the contribution @deeplow!

@redshiftzero redshiftzero merged commit 610ac9f into freedomofpress:master Oct 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Warning raised during deletion
2 participants