diff --git a/0000-Do-not-allow-NULL-values-to-be-stored-in-the-Comment.patch b/0000-Do-not-allow-NULL-values-to-be-stored-in-the-Comment.patch new file mode 100644 index 0000000..98674fb --- /dev/null +++ b/0000-Do-not-allow-NULL-values-to-be-stored-in-the-Comment.patch @@ -0,0 +1,71 @@ +From 4b67d5fd4ec1abbf8099c52c2a118e765490ce35 Mon Sep 17 00:00:00 2001 +From: Randy Barlow +Date: Wed, 21 Sep 2016 18:19:50 -0400 +Subject: [PATCH] Do not allow NULL values to be stored in the Comment.text + column. + +This commit disallows the Comment.text column to contain NULL +values. Additionally, it contains a data migration to convert all +NULL values to the empty string. + +fixes #949 +--- + alembic/versions/37f38ddc4c8d_.py | 32 ++++++++++++++++++++++++++++++++ + bodhi/server/models/models.py | 2 +- + 2 files changed, 33 insertions(+), 1 deletion(-) + create mode 100644 alembic/versions/37f38ddc4c8d_.py + +diff --git a/alembic/versions/37f38ddc4c8d_.py b/alembic/versions/37f38ddc4c8d_.py +new file mode 100644 +index 0000000..824808a +--- /dev/null ++++ b/alembic/versions/37f38ddc4c8d_.py +@@ -0,0 +1,32 @@ ++"""Do not allow NULL values in the text column of the comments table. ++ ++Revision ID: 37f38ddc4c8d ++Revises: 4df1fcd59050 ++Create Date: 2016-09-21 19:51:04.946521 ++ ++""" ++ ++from alembic import op ++import sqlalchemy as sa ++ ++ ++# revision identifiers, used by Alembic. ++revision = '37f38ddc4c8d' ++down_revision = '4df1fcd59050' ++ ++ ++def upgrade(): ++ """ ++ We will need to set all existing NULL comments to "", then change the column to disallow NULL comments. ++ """ ++ # Build a fake mini version of the comments table so we can form an UPDATE statement. ++ comments = sa.sql.table('comments', sa.sql.column('text', sa.UnicodeText)) ++ # Set existing NULL comments to "". ++ op.execute(comments.update().where(comments.c.text==None).values({'text': op.inline_literal('')})) ++ ++ # Disallow new NULL comments. ++ op.alter_column('comments', 'text', existing_type=sa.TEXT(), nullable=False) ++ ++ ++def downgrade(): ++ op.alter_column('comments', 'text', existing_type=sa.TEXT(), nullable=True) +diff --git a/bodhi/server/models/models.py b/bodhi/server/models/models.py +index f096d23..df34891 100644 +--- a/bodhi/server/models/models.py ++++ b/bodhi/server/models/models.py +@@ -1904,7 +1904,7 @@ class Comment(Base): + + karma = Column(Integer, default=0) + karma_critpath = Column(Integer, default=0) +- text = Column(UnicodeText) ++ text = Column(UnicodeText, nullable=False) + anonymous = Column(Boolean, default=False) + timestamp = Column(DateTime, default=datetime.utcnow) + +-- +2.10.0 + diff --git a/bodhi.spec b/bodhi.spec index 0bb1f8d..f27aa1b 100644 --- a/bodhi.spec +++ b/bodhi.spec @@ -3,19 +3,22 @@ Name: bodhi Version: 2.2.1 -Release: 2%{?dist} +Release: 3%{?dist} Summary: A modular framework that facilitates publishing software updates Group: Applications/Internet License: GPLv2+ URL: https://github.com/fedora-infra/bodhi Source0: https://github.com/fedora-infra/bodhi/archive/%{version}.tar.gz +# This patch is already merged upstream in the 2.2 and develop branches, but is not part of an +# upstream release yet. +Patch0: 0000-Do-not-allow-NULL-values-to-be-stored-in-the-Comment.patch # There is a problem where comments can be NULL in the database. This patch doesn't # fix that problem, but it does fix template rendering on updates that have such comments. # See https://github.com/fedora-infra/bodhi/issues/949 -Patch0: 0001-Only-put-the-comment-through-markdown-if-there-is-a-.patch +Patch1: 0001-Only-put-the-comment-through-markdown-if-there-is-a-.patch # This patch is already merged upstream in the 2.2 and develop branches, but is not part of an # upstream release yet. -Patch1: 0002-Sometimes-we-have-no-mash-so-dont-wait-for-mash_thre.patch +Patch2: 0002-Sometimes-we-have-no-mash-so-dont-wait-for-mash_thre.patch BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) BuildArch: noarch ExcludeArch: ppc64 ppc @@ -208,6 +211,7 @@ updates for a software distribution. %patch0 -p1 %patch1 -p1 +%patch2 -p1 # Kill some dev deps sed -i '/pyramid_debugtoolbar/d' setup.py @@ -322,6 +326,9 @@ PYTHONPATH=. %{__python} setup.py test %changelog +* Fri Sep 23 2016 Randy Barlow - 2.2.1-3 +- Add a patch to disallow NULL text on the Comment model. + * Fri Sep 23 2016 Randy Barlow - 2.2.1-2 - Add a patch to skip waiting on a mash thread if there isn't one.