<html><body>
<p>New issue 217: upgrade-db fails to fix auth modules after rebranddb.py <a href="https://bitbucket.org/conservancy/kallithea/issues/217/upgrade-db-fails-to-fix-auth-modules-after">https://bitbucket.org/conservancy/kallithea/issues/217/upgrade-db-fails-to-fix-auth-modules-after</a></p>
<p>Matthias Langhammer:</p>
<p>While upgrading from RhodeCode 1.7.1 to Kallithea 0.3.2 I faced the following problem during the database migration:</p>
<p>``` <strong>********************************</strong>* <strong>*</strong> FIXING DEFAULT AUTH MODULES <strong>*</strong> <strong>********************************</strong>* Traceback (most recent call last):</p>
<pre>File "/tmp/rhodecodetest/system/bin/paster", line 11, in <module>
  sys.exit(run())
File "/tmp/rhodecodetest/system/local/lib/python2.7/site-packages/paste/script/command.py", line 102, in run
  invoke(command, command_name, options, args[1:])
File "/tmp/rhodecodetest/system/local/lib/python2.7/site-packages/paste/script/command.py", line 141, in invoke
  exit_code = runner.run(args)
File "/tmp/rhodecodetest/system/local/lib/python2.7/site-packages/kallithea/lib/utils.py", line 752, in run
  return super(BasePasterCommand, self).run(args[1:])
File "/tmp/rhodecodetest/system/local/lib/python2.7/site-packages/paste/script/command.py", line 236, in run
  result = self.command()
File "/tmp/rhodecodetest/system/local/lib/python2.7/site-packages/kallithea/lib/dbmigrate/__init__.py", line 57, in command
  dbmanage.upgrade()
File "/tmp/rhodecodetest/system/local/lib/python2.7/site-packages/kallithea/lib/db_manage.py", line 175, in upgrade
  api.upgrade(db_uri, repository_path, step)
File "/tmp/rhodecodetest/system/local/lib/python2.7/site-packages/kallithea/lib/dbmigrate/migrate/versioning/api.py", line 186, in upgrade
  return _migrate(url, repository, version, upgrade=True, err=err, **opts)
File "<decorator-gen-16>", line 2, in _migrate
File "/tmp/rhodecodetest/system/local/lib/python2.7/site-packages/kallithea/lib/dbmigrate/migrate/versioning/util/__init__.py", line 159, in with_engine
  return f(*a, **kw)
File "/tmp/rhodecodetest/system/local/lib/python2.7/site-packages/kallithea/lib/dbmigrate/migrate/versioning/api.py", line 366, in _migrate
  schema.runchange(ver, change, changeset.step)
File "/tmp/rhodecodetest/system/local/lib/python2.7/site-packages/kallithea/lib/dbmigrate/migrate/versioning/schema.py", line 92, in runchange
  change.run(self.engine, step)
File "/tmp/rhodecodetest/system/local/lib/python2.7/site-packages/kallithea/lib/dbmigrate/migrate/versioning/script/py.py", line 145, in run
  script_func(engine)
File "/tmp/rhodecodetest/system/lib/python2.7/site-packages/kallithea/lib/dbmigrate/versions/018_version_2_0_0.py", line 24, in upgrade
  fixups(db_2_0_0, meta.Session)
File "/tmp/rhodecodetest/system/lib/python2.7/site-packages/kallithea/lib/dbmigrate/versions/018_version_2_0_0.py", line 69, in fixups
  setting = models.Setting(name, old_setting.app_settings_value, t)</pre>
<p>AttributeError: ‘NoneType’ object has no attribute ‘app_settings_value’ ```</p>
<p>The problem appears while LDAP settings (which did not exist in the old database) are converted to the new format with ‘auth_’ as prefix. The script crashes when trying to access the attribute ‘app_settings_value’ from an old_setting which does not exist. So instead of using the non-existing old value, the default value ‘v’ should be used.</p>
<p>I fixed this by editing the file lib/dbmigrate/versions/018_version_2_0_0.py .</p>
<p>I replaced</p>
<p>``` #!python</p>
<pre>    for k, v, t in old_ldap:
        old_setting = models.Setting.get_by_name(k)
        name = 'auth_%s' % k
        setting = models.Setting.get_by_name(name)
        if not setting:
# if we don't have this option create it
setting = models.Setting(name, old_setting.app_settings_value, t)</pre>
<p>``` with</p>
<p>``` #!python</p>
<pre>    for k, v, t in old_ldap:
        old_setting = models.Setting.get_by_name(k)
        name = 'auth_%s' % k
        setting = models.Setting.get_by_name(name)
        if not setting:
# if we don't have this option create it
setting = models.Setting(name, v, t)</pre>
<p>```</p>
<p>With this patch I was able to compelte the migration.</p>

<img src="http://link.bitbucket.org/wf/open?upn=7V-2FmRl-2BatdmBwUBFXbsB13NVJlEXqBigXyxfn0HY8gb734ofWR-2Fbbq5jwybzy1EM-2FqIp4rmeaknfHyQomT2PZANsHdSLLcKpPIGmjBTdfStQbkUlACMRXaEaZwThrSV7g-2FFgW-2FU9T8hWrzvq8bik0N-2BrJQd5UwQ9klMDU71TnSFnH3dMb7RF8RM9Q6Y4jb8Nv9UXJDQtafUUsLIHpFEEd3FCgSWfLgNTdPkh6XCxt3UwVilWyCEdZ4K42mvrKkGc" alt="" width="1" height="1" border="0" style="height:1px !important;width:1px !important;border-width:0 !important;margin-top:0 !important;margin-bottom:0 !important;margin-right:0 !important;margin-left:0 !important;padding-top:0 !important;padding-bottom:0 !important;padding-right:0 !important;padding-left:0 !important;"/>
</body></html>