Repository: freedomofpress/securedrop

Issue:
Run flake8 against alembic migrations
*This is a good first issue for new contributors to take on, if you have any questions, please ask on the task or in our [Gitter room](https://gitter.im/freedomofpress/securedrop)!*

## Description

In `.flake8` we currently exclude `securedrop/alembic/versions`. We should be running flake8 against those files by removing the exclusion and fixing any new flake8 errors.


Discussion:
Hi, I would to work on it. Could you please assign it to me? Thanks!

Resolving patch:
diff --git a/securedrop/alembic/versions/2e24fc7536e8_make_journalist_id_non_nullable.py b/securedrop/alembic/versions/2e24fc7536e8_make_journalist_id_non_nullable.py
--- a/securedrop/alembic/versions/2e24fc7536e8_make_journalist_id_non_nullable.py
+++ b/securedrop/alembic/versions/2e24fc7536e8_make_journalist_id_non_nullable.py
@@ -82,14 +82,15 @@ def migrate_nulls() -> None:
 
     deleted_id = create_deleted()
     for table in needs_migration:
-        # The seen_ tables have UNIQUE(fk_id, journalist_id), so the deleted journalist can only have
-        # seen each item once. It is possible multiple NULL journalist have seen the same thing so we
-        # do this update in two passes.
+        # The seen_ tables have UNIQUE(fk_id, journalist_id), so the deleted journalist can only
+        # have seen each item once. It is possible multiple NULL journalist have seen the same thing
+        # so we do this update in two passes.
         # First we update as many rows to point to the deleted journalist as possible, ignoring any
         # unique key violations.
         op.execute(
             sa.text(
-                f"UPDATE OR IGNORE {table} SET journalist_id=:journalist_id WHERE journalist_id IS NULL;"
+                f"UPDATE OR IGNORE {table} SET journalist_id=:journalist_id "
+                "WHERE journalist_id IS NULL;"
             ).bindparams(journalist_id=deleted_id)
         )
         # Then we delete any leftovers which had been ignored earlier.
diff --git a/securedrop/alembic/versions/b7f98cfd6a70_make_filesystem_id_non_nullable.py b/securedrop/alembic/versions/b7f98cfd6a70_make_filesystem_id_non_nullable.py
--- a/securedrop/alembic/versions/b7f98cfd6a70_make_filesystem_id_non_nullable.py
+++ b/securedrop/alembic/versions/b7f98cfd6a70_make_filesystem_id_non_nullable.py
@@ -19,8 +19,8 @@ def upgrade() -> None:
     # Not having a filesystem_id makes the source useless, so if any of those do exist, we'll
     # delete them first, as part of this migration.
     # Because we can't rely on SQLAlchemy's cascade deletion, we have to do it manually.
-    # First we delete out of replies/seen_files/seen_messages (things that refer to things that refer
-    # to sources)
+    # First we delete out of replies/seen_files/seen_messages (things that refer to things
+    # (source_stars/submissions/replies) that refer to sources)
     op.execute(
         "DELETE FROM seen_replies WHERE reply_id IN ("
         "SELECT replies.id FROM replies "
diff --git a/securedrop/alembic/versions/c5a02eb52f2d_dropped_session_nonce_from_journalist_.py b/securedrop/alembic/versions/c5a02eb52f2d_dropped_session_nonce_from_journalist_.py
--- a/securedrop/alembic/versions/c5a02eb52f2d_dropped_session_nonce_from_journalist_.py
+++ b/securedrop/alembic/versions/c5a02eb52f2d_dropped_session_nonce_from_journalist_.py
@@ -1,4 +1,5 @@
-"""dropped session_nonce from journalist table and revoked tokens table due to new session implementation
+"""dropped session_nonce from journalist table and revoked tokens table
+   due to new session implementation
 
 Revision ID: c5a02eb52f2d
 Revises: b7f98cfd6a70
@@ -27,7 +28,8 @@ def upgrade() -> None:
 def downgrade() -> None:
     """This would have been the easy way, however previous does not have
     default value and thus up/down assertion fails"""
-    # op.add_column('journalists', sa.Column('session_nonce', sa.Integer(), nullable=False, server_default='0'))
+    # op.add_column('journalists', sa.Column('session_nonce', sa.Integer(),
+    #               nullable=False, server_default='0'))
 
     conn = op.get_bind()
     conn.execute("PRAGMA legacy_alter_table=ON")


Test patch: