Multiple rows were found for one()

Issue #752 resolved
Matthew Black created an issue

Clicking on a repository group since upgrading from 1.5.1 to 1.5.2 is giving this error message.

Mon Feb 04 22:47:45 2013] [error] [client ] Error - <class 'sqlalchemy.orm.exc.MultipleResultsFound'>: Multiple rows were found for one()
[Mon Feb 04 22:47:45 2013] [error] [client ] URL: https://repos.xxxxxx.xxxx/Puppet
[Mon Feb 04 22:47:45 2013] [error] [client ] File '/usr/local/lib/python2.6/dist-packages/weberror/errormiddleware.py', line 162 in __call__
[Mon Feb 04 22:47:45 2013] [error] [client ]   app_iter = self.application(environ, sr_checker)
[Mon Feb 04 22:47:45 2013] [error] [client ] File '/usr/local/lib/python2.6/dist-packages/beaker/middleware.py', line 155 in __call__
[Mon Feb 04 22:47:45 2013] [error] [client ]   return self.wrap_app(environ, session_start_response)
[Mon Feb 04 22:47:45 2013] [error] [client ] File '/usr/local/lib/python2.6/dist-packages/routes/middleware.py', line 131 in __call__
[Mon Feb 04 22:47:45 2013] [error] [client ]   response = self.app(environ, start_response)
[Mon Feb 04 22:47:45 2013] [error] [client ] File '/usr/local/lib/python2.6/dist-packages/Pylons-1.0-py2.6.egg/pylons/wsgiapp.py', line 107 in __call__
[Mon Feb 04 22:47:45 2013] [error] [client ]   response = self.dispatch(controller, environ, start_response)
[Mon Feb 04 22:47:45 2013] [error] [client ] File '/usr/local/lib/python2.6/dist-packages/Pylons-1.0-py2.6.egg/pylons/wsgiapp.py', line 312 in dispatch
[Mon Feb 04 22:47:45 2013] [error] [client ]   return controller(environ, start_response)
[Mon Feb 04 22:47:45 2013] [error] [client ] File '/usr/local/lib/python2.6/dist-packages/rhodecode/lib/base.py', line 300 in __call__
[Mon Feb 04 22:47:45 2013] [error] [client ]   return WSGIController.__call__(self, environ, start_response)
[Mon Feb 04 22:47:45 2013] [error] [client ] File '/usr/local/lib/python2.6/dist-packages/Pylons-1.0-py2.6.egg/pylons/controllers/core.py', line 211 in __call__
[Mon Feb 04 22:47:45 2013] [error] [client ]   response = self._dispatch_call()
[Mon Feb 04 22:47:45 2013] [error] [client ] File '/usr/local/lib/python2.6/dist-packages/Pylons-1.0-py2.6.egg/pylons/controllers/core.py', line 162 in _dispatch_call
[Mon Feb 04 22:47:45 2013] [error] [client ]   response = self._inspect_call(func)
[Mon Feb 04 22:47:45 2013] [error] [client ] File '/usr/local/lib/python2.6/dist-packages/Pylons-1.0-py2.6.egg/pylons/controllers/core.py', line 105 in _inspect_call
[Mon Feb 04 22:47:45 2013] [error] [client ]   result = self._perform_call(func, args)
[Mon Feb 04 22:47:45 2013] [error] [client ] File '/usr/local/lib/python2.6/dist-packages/Pylons-1.0-py2.6.egg/pylons/controllers/core.py', line 57 in _perform_call
[Mon Feb 04 22:47:45 2013] [error] [client ]   return func(**args)
[Mon Feb 04 22:47:45 2013] [error] [client ] File '/usr/local/lib/python2.6/dist-packages/rhodecode/controllers/admin/repos_groups.py', line 277 in show_by_name
[Mon Feb 04 22:47:45 2013] [error] [client ]   return self.show(id_.group_id)
[Mon Feb 04 22:47:45 2013] [error] [client ] File '<string>', line 2 in show
[Mon Feb 04 22:47:45 2013] [error] [client ] File '/usr/local/lib/python2.6/dist-packages/rhodecode/lib/auth.py', line 583 in __wrapper
[Mon Feb 04 22:47:45 2013] [error] [client ]   return func(*fargs, **fkwargs)
[Mon Feb 04 22:47:45 2013] [error] [client ] File '/usr/local/lib/python2.6/dist-packages/rhodecode/controllers/admin/repos_groups.py', line 311 in show
[Mon Feb 04 22:47:45 2013] [error] [client ]   return render('admin/repos_groups/repos_groups.html')
[Mon Feb 04 22:47:45 2013] [error] [client ] File '/usr/local/lib/python2.6/dist-packages/Pylons-1.0-py2.6.egg/pylons/templating.py', line 243 in render_mako
[Mon Feb 04 22:47:45 2013] [error] [client ]   cache_type=cache_type, cache_expire=cache_expire)
[Mon Feb 04 22:47:45 2013] [error] [client ] File '/usr/local/lib/python2.6/dist-packages/Pylons-1.0-py2.6.egg/pylons/templating.py', line 218 in cached_template
[Mon Feb 04 22:47:45 2013] [error] [client ]   return render_func()
[Mon Feb 04 22:47:45 2013] [error] [client ] File '/usr/local/lib/python2.6/dist-packages/Pylons-1.0-py2.6.egg/pylons/templating.py', line 240 in render_template
[Mon Feb 04 22:47:45 2013] [error] [client ]   return literal(template.render_unicode(**globs))
[Mon Feb 04 22:47:45 2013] [error] [client ] File '/usr/local/lib/python2.6/dist-packages/mako/template.py', line 421 in render_unicode
[Mon Feb 04 22:47:45 2013] [error] [client ]   as_unicode=True)
[Mon Feb 04 22:47:45 2013] [error] [client ] File '/usr/local/lib/python2.6/dist-packages/mako/runtime.py', line 766 in _render
[Mon Feb 04 22:47:45 2013] [error] [client ]   **_kwargs_for_callable(callable_, data))
[Mon Feb 04 22:47:45 2013] [error] [client ] File '/usr/local/lib/python2.6/dist-packages/mako/runtime.py', line 798 in _render_context
[Mon Feb 04 22:47:45 2013] [error] [client ]   _exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
[Mon Feb 04 22:47:45 2013] [error] [client ] File '/usr/local/lib/python2.6/dist-packages/mako/runtime.py', line 819 in _exec_template
[Mon Feb 04 22:47:45 2013] [error] [client ]   _render_error(template, context, e)
[Mon Feb 04 22:47:45 2013] [error] [client ] File '/usr/local/lib/python2.6/dist-packages/mako/runtime.py', line 828 in _render_error
[Mon Feb 04 22:47:45 2013] [error] [client ]   result = template.error_handler(context, error)
[Mon Feb 04 22:47:45 2013] [error] [client ] File '/usr/local/lib/python2.6/dist-packages/mako/runtime.py', line 817 in _exec_template
[Mon Feb 04 22:47:45 2013] [error] [client ]   callable_(context, *args, **kwargs)
[Mon Feb 04 22:47:45 2013] [error] [client ] File '/var/www/rhode/data/templates/base/root.html.py', line 68 in render_body
[Mon Feb 04 22:47:45 2013] [error] [client ]   __M_writer(escape(next.body()))
[Mon Feb 04 22:47:45 2013] [error] [client ] File '/var/www/rhode/data/templates/base/base.html.py', line 73 in render_body
[Mon Feb 04 22:47:45 2013] [error] [client ]   __M_writer(escape(next.main()))
[Mon Feb 04 22:47:45 2013] [error] [client ] File '/var/www/rhode/data/templates/admin/repos_groups/repos_groups.html.py', line 55 in render_main
[Mon Feb 04 22:47:45 2013] [error] [client ]   runtime._include_file(context, u'/index_base.html', _template_uri, parent=self,short_repo_names=True)
[Mon Feb 04 22:47:45 2013] [error] [client ] File '/usr/local/lib/python2.6/dist-packages/mako/runtime.py', line 693 in _include_file
[Mon Feb 04 22:47:45 2013] [error] [client ]   callable_(ctx, **_kwargs_for_include(callable_, context._data, **kwargs))
[Mon Feb 04 22:47:45 2013] [error] [client ] File '/var/www/rhode/data/templates/index_base.html.py', line 152 in render_body
[Mon Feb 04 22:47:45 2013] [error] [client ]   for cnt,repo in enumerate(c.repos_list):
[Mon Feb 04 22:47:45 2013] [error] [client ] File '/usr/local/lib/python2.6/dist-packages/rhodecode/model/scm.py', line 98 in __iter__
[Mon Feb 04 22:47:45 2013] [error] [client ]   scmr = dbr.scm_instance_cached(cache_map)
[Mon Feb 04 22:47:45 2013] [error] [client ] File '/usr/local/lib/python2.6/dist-packages/rhodecode/model/db.py', line 1096 in scm_instance_cached
[Mon Feb 04 22:47:45 2013] [error] [client ]   CacheInvalidation.set_valid(invalidate_repo.cache_key)
[Mon Feb 04 22:47:45 2013] [error] [client ] File '/usr/local/lib/python2.6/dist-packages/rhodecode/model/db.py', line 1652 in set_valid
[Mon Feb 04 22:47:45 2013] [error] [client ]   inv_obj = cls.get_by_key(key)
[Mon Feb 04 22:47:45 2013] [error] [client ] File '/usr/local/lib/python2.6/dist-packages/rhodecode/model/db.py', line 1579 in get_by_key
[Mon Feb 04 22:47:45 2013] [error] [client ]   return cls.query().filter(cls.cache_key == key).scalar()
[Mon Feb 04 22:47:45 2013] [error] [client ] File '/usr/local/lib/python2.6/dist-packages/sqlalchemy/orm/query.py', line 2215 in scalar
[Mon Feb 04 22:47:45 2013] [error] [client ]   ret = self.one()
[Mon Feb 04 22:47:45 2013] [error] [client ] File '/usr/local/lib/python2.6/dist-packages/sqlalchemy/orm/query.py', line 2193 in one
[Mon Feb 04 22:47:45 2013] [error] [client ]   "Multiple rows were found for one()")
[Mon Feb 04 22:47:45 2013] [error] [client ] MultipleResultsFound: Multiple rows were found for one()

Comments (8)

  1. Matthew Black reporter

    I'm seeing that the issue is related to the table cache_invalidation is having duplicate records. When I delete the duplicates it works fine.

    Not sure what happened to cause it but maybe a uniqueness clause is needed to prevent additional records with the same repo name to be created?

  2. Marcin Kuzminski repo owner

    this table has an Unique check on cache_key column, was that the one that got duplicates ? Maybe it's a db migration issue ?

  3. Matthew Black reporter

    Yes that was the one with the duplicate entries.

    I'm not too familiar with how python web applications do database migrations but I did do an upgrade to 1.5.2 a week or two back and shortly after that was when the problems began.

  4. Marcin Kuzminski repo owner

    Sorry to hear that :(, the migration library that RhodeCode uses isn't very good unfortunately. from what version did you upgrade ? Please put an unique index for that key if it's not existing in your database.

  5. Matthew Black reporter

    Ah yes, I didnt think to check that, the column was not set to unique.

    I believe if I remember correctly, too much going on, that it was from 1.5.1 to 1.5.2

  6. Log in to comment