Repository: fedora-infra/bodhi

Issue:
400 Bad Request when associating bugs with updates
When I fixed #3016 yesterday, I ended up reverting the commit https://github.com/fedora-infra/bodhi/commit/be369636529f3d637f9888bf658d77adac2e9b8b. I opted not to remove the new private field, since technically it became part of the API, if even for only a day, and that would be a backwards incompatible change. Instead, I wrote a migration to drop the field for the upcoming 4.0.0 release.

The problem is that the field is required to be non-null. This prevents users from adding new bugs to Bodhi, because there is no longer any code to set the field, but it is required. Requests to add bugs to updates will receive a 400 Bad Request response:

Unable to create update. (psycopg2.IntegrityError) null value in column "private" violates not-null constraint DETAIL: Failing row contains (52898, 1671171, null, f, f, null). [SQL: 'INSERT INTO bugs (bug_id, title, security, parent) VALUES (%(bug_id)s, %(title)s, %(security)s, %(parent)s) RETURNING bugs.id'] [parameters: {'bug_id': 1671171, 'title': None, 'security': False, 'parent': False}] (Background on this error at: http://sqlalche.me/e/gkpj)

The fix is to write a migration that make this field nullable.


Discussion:
# Workaround

If you are experiencing this problem, a workaround is to avoid associating bugs with your updates until we can get this fixed.

Resolving patch:
diff --git a/bodhi/server/migrations/versions/8e9dc57e082d_obsolete_updates_for_archived_release.py b/bodhi/server/migrations/versions/8e9dc57e082d_obsolete_updates_for_archived_release.py
--- a/bodhi/server/migrations/versions/8e9dc57e082d_obsolete_updates_for_archived_release.py
+++ b/bodhi/server/migrations/versions/8e9dc57e082d_obsolete_updates_for_archived_release.py
@@ -20,7 +20,7 @@
 Obsolete updates for archived release.
 
 Revision ID: 8e9dc57e082d
-Revises: d986618207bc
+Revises: 9991cf10ec50
 Create Date: 2019-01-06 13:04:35.158562
 """
 from alembic import op
@@ -28,7 +28,7 @@
 
 # revision identifiers, used by Alembic.
 revision = '8e9dc57e082d'
-down_revision = 'd986618207bc'
+down_revision = '9991cf10ec50'
 
 
 def upgrade():
diff --git a/bodhi/server/migrations/versions/9991cf10ec50_mark_the_bugs_private_field_as_nullable.py b/bodhi/server/migrations/versions/9991cf10ec50_mark_the_bugs_private_field_as_nullable.py
new file mode 100644
--- /dev/null
+++ b/bodhi/server/migrations/versions/9991cf10ec50_mark_the_bugs_private_field_as_nullable.py
@@ -0,0 +1,41 @@
+# Copyright (c) 2019 Red Hat, Inc.
+#
+# This file is part of Bodhi.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+"""
+Mark the bugs.private field as nullable.
+
+Revision ID: 9991cf10ec50
+Revises: d986618207bc
+Create Date: 2019-02-19 15:54:53.058707
+"""
+from alembic import op
+
+
+# revision identifiers, used by Alembic.
+revision = '9991cf10ec50'
+down_revision = 'd986618207bc'
+
+
+def upgrade():
+    """Set the bugs.private column to be nullable."""
+    op.alter_column('bugs', 'private', nullable=True)
+
+
+def downgrade():
+    """Set the bugs.private column to be non-nullable."""
+    op.execute("""UPDATE bugs SET private = FALSE WHERE private = NULL""")
+    op.alter_column('bugs', 'private', nullable=False)
diff --git a/bodhi/server/migrations/versions/aae0d29d49b7_remove_the_private_field_on_the_bug_.py b/bodhi/server/migrations/versions/aae0d29d49b7_remove_the_private_field_on_the_bug_.py
--- a/bodhi/server/migrations/versions/aae0d29d49b7_remove_the_private_field_on_the_bug_.py
+++ b/bodhi/server/migrations/versions/aae0d29d49b7_remove_the_private_field_on_the_bug_.py
@@ -39,5 +39,3 @@ def upgrade():
 def downgrade():
     """Add the private field back to the bugs table."""
     op.add_column('bugs', sa.Column('private', sa.BOOLEAN(), autoincrement=False, nullable=True))
-    op.execute("""UPDATE bugs SET private = FALSE""")
-    op.alter_column('bugs', 'private', nullable=False)


Test patch: