Repository: fedora-infra/bodhi

Issue:
psycopg2.IntegrityError: column "display_name" contains null values
I broke Bodhi ☹

```
[vagrant@bodhi-dev bodhi]$ alembic upgrade head                                            
INFO  [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO  [alembic.runtime.migration] Will assume transactional DDL.                                     
INFO  [alembic.runtime.migration] Running upgrade 22858ba91115 -> be25565a1211, Add a dislay_name field to the updates table.
Traceback (most recent call last):                                                               
  File "/usr/lib64/python3.6/site-packages/sqlalchemy/engine/base.py", line 1182, in _execute_context
    context)                                                                                         
  File "/usr/lib64/python3.6/site-packages/sqlalchemy/engine/default.py", line 470, in do_execute
    cursor.execute(statement, parameters)                                                                   
psycopg2.IntegrityError: column "display_name" contains null values
                                                                                                    
                                                               
The above exception was the direct cause of the following exception:                       
                                  
Traceback (most recent call last):                                                                   
  File "/usr/local/bin/alembic", line 11, in <module>
    load_entry_point('alembic', 'console_scripts', 'alembic')()                                  
  File "/usr/local/lib/python3.6/site-packages/alembic-0.9.9-py3.6.egg/alembic/config.py", line 486, in main
    CommandLine(prog=prog).main(argv=argv)                                                         
  File "/usr/local/lib/python3.6/site-packages/alembic-0.9.9-py3.6.egg/alembic/config.py", line 480, in main
    self.run_cmd(cfg, options)
  File "/usr/local/lib/python3.6/site-packages/alembic-0.9.9-py3.6.egg/alembic/config.py", line 463, in run_cmd
    **dict((k, getattr(options, k, None)) for k in kwarg)
  File "/usr/local/lib/python3.6/site-packages/alembic-0.9.9-py3.6.egg/alembic/command.py", line 254, in upgrade
    script.run_env()
  File "/usr/local/lib/python3.6/site-packages/alembic-0.9.9-py3.6.egg/alembic/script/base.py", line 427, in run_env
    util.load_python_file(self.dir, 'env.py')
  File "/usr/local/lib/python3.6/site-packages/alembic-0.9.9-py3.6.egg/alembic/util/pyfiles.py", line 81, in load_python_file                                                                                                                
    module = load_module_py(module_id, path)
  File "/usr/local/lib/python3.6/site-packages/alembic-0.9.9-py3.6.egg/alembic/util/compat.py", line 83, in load_module_py                                                                                                                   
    spec.loader.exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/vagrant/bodhi/bodhi/server/migrations/env.py", line 112, in <module>
    run_migrations_online()
  File "/home/vagrant/bodhi/bodhi/server/migrations/env.py", line 104, in run_migrations_online
    context.run_migrations()
  File "<string>", line 8, in run_migrations
  File "/usr/local/lib/python3.6/site-packages/alembic-0.9.9-py3.6.egg/alembic/runtime/environment.py", line 836, in run_migrations                                                                                                          
    self.get_context().run_migrations(**kw)
  File "/usr/local/lib/python3.6/site-packages/alembic-0.9.9-py3.6.egg/alembic/runtime/migration.py", line 330, in run_migrations                                                                                                            
    step.migration_fn(**kw)
  File "/home/vagrant/bodhi/bodhi/server/migrations/versions/be25565a1211_add_a_dislay_name_field_to_the_updates_.py", line 36, in upgrade                                                                                                   
    op.add_column('updates', sa.Column('display_name', sa.UnicodeText(), nullable=False))
  File "<string>", line 8, in add_column
  File "<string>", line 3, in add_column
  File "/usr/local/lib/python3.6/site-packages/alembic-0.9.9-py3.6.egg/alembic/operations/ops.py", line 1565, in add_column                                                                                                                  
    return operations.invoke(op)
  File "/usr/local/lib/python3.6/site-packages/alembic-0.9.9-py3.6.egg/alembic/operations/base.py", line 319, in invoke                                                                                                                      
    return fn(self, operation)
  File "/usr/local/lib/python3.6/site-packages/alembic-0.9.9-py3.6.egg/alembic/operations/toimpl.py", line 123, in add_column                                                                                                                
    schema=schema
  File "/usr/local/lib/python3.6/site-packages/alembic-0.9.9-py3.6.egg/alembic/ddl/impl.py", line 172, in add_column
    self._exec(base.AddColumn(table_name, column, schema=schema))
  File "/usr/local/lib/python3.6/site-packages/alembic-0.9.9-py3.6.egg/alembic/ddl/impl.py", line 118, in _exec
    return conn.execute(construct, *multiparams, **params)
  File "/usr/lib64/python3.6/site-packages/sqlalchemy/engine/base.py", line 945, in execute
    return meth(self, multiparams, params)
  File "/usr/lib64/python3.6/site-packages/sqlalchemy/sql/ddl.py", line 68, in _execute_on_connection
    return connection._execute_ddl(self, multiparams, params)
  File "/usr/lib64/python3.6/site-packages/sqlalchemy/engine/base.py", line 1002, in _execute_ddl
    compiled
  File "/usr/lib64/python3.6/site-packages/sqlalchemy/engine/base.py", line 1189, in _execute_context
    context)
  File "/usr/lib64/python3.6/site-packages/sqlalchemy/engine/base.py", line 1402, in _handle_dbapi_exception
    exc_info
  File "/usr/lib64/python3.6/site-packages/sqlalchemy/util/compat.py", line 203, in raise_from_cause
    reraise(type(exception), exception, tb=exc_tb, cause=cause)
  File "/usr/lib64/python3.6/site-packages/sqlalchemy/util/compat.py", line 186, in reraise
    raise value.with_traceback(tb)
  File "/usr/lib64/python3.6/site-packages/sqlalchemy/engine/base.py", line 1182, in _execute_context
    context)
  File "/usr/lib64/python3.6/site-packages/sqlalchemy/engine/default.py", line 470, in do_execute
    cursor.execute(statement, parameters)
sqlalchemy.exc.IntegrityError: (psycopg2.IntegrityError) column "display_name" contains null values
 [SQL: 'ALTER TABLE updates ADD COLUMN display_name TEXT NOT NULL']
```


Discussion:

Resolving patch:
diff --git a/bodhi/server/migrations/versions/be25565a1211_add_a_dislay_name_field_to_the_updates_.py b/bodhi/server/migrations/versions/be25565a1211_add_a_dislay_name_field_to_the_updates_.py
--- a/bodhi/server/migrations/versions/be25565a1211_add_a_dislay_name_field_to_the_updates_.py
+++ b/bodhi/server/migrations/versions/be25565a1211_add_a_dislay_name_field_to_the_updates_.py
@@ -16,7 +16,7 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 """
-Add a dislay_name field to the updates table.
+Add a display_name field to the updates table.
 
 Revision ID: be25565a1211
 Revises: 22858ba91115
@@ -33,7 +33,8 @@
 
 def upgrade():
     """Add a display_name column to the updates table."""
-    op.add_column('updates', sa.Column('display_name', sa.UnicodeText(), nullable=False))
+    op.add_column('updates', sa.Column('display_name', sa.UnicodeText(), nullable=False,
+                  server_default=u''))
 
 
 def downgrade():
diff --git a/bodhi/server/models.py b/bodhi/server/models.py
--- a/bodhi/server/models.py
+++ b/bodhi/server/models.py
@@ -1699,7 +1699,7 @@ class Update(Base):
     require_bugs = Column(Boolean, default=False)
     require_testcases = Column(Boolean, default=False)
 
-    display_name = Column(UnicodeText, nullable=False, default='')
+    display_name = Column(UnicodeText, nullable=False, default=u'')
     notes = Column(UnicodeText, nullable=False)  # Mandatory notes
 
     # Enumerated types


Test patch: