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/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)


Test patch: