1. Marcin Kuzminski
  2. RhodeCode
  3. Issues

Issues

Issue #772 resolved

Duplicate entry '1-3' for key 'users_group_id'

Denis Blanchette
created an issue

Since we upgraded to RhodeCode 1.5.2, we were unable to add a user group in the permissions of a repository.

The log indicates the following :

[Tue Feb 19 09:56:01 2013] [error]   File "/usr/local/lib/python2.6/dist-packages/RhodeCode-1.5.2-py2.6.egg/rhodecode/controllers/admin/repos.py", line 240, in update
[Tue Feb 19 09:56:01 2013] [error]     repo = repo_model.update(repo_name, **form_result)
[Tue Feb 19 09:56:01 2013] [error]   File "/usr/local/lib/python2.6/dist-packages/RhodeCode-1.5.2-py2.6.egg/rhodecode/model/repo.py", line 298, in update
[Tue Feb 19 09:56:01 2013] [error]     cur_repo.user = User.get_by_username(kwargs['user'])
[Tue Feb 19 09:56:01 2013] [error]   File "/usr/local/lib/python2.6/dist-packages/RhodeCode-1.5.2-py2.6.egg/rhodecode/model/db.py", line 419, in get_by_username
[Tue Feb 19 09:56:01 2013] [error]     return q.scalar()
[Tue Feb 19 09:56:01 2013] [error]   File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.7.9-py2.6-linux-x86_64.egg/sqlalchemy/orm/query.py", line 2215, in scalar
[Tue Feb 19 09:56:01 2013] [error]     ret = self.one()
[Tue Feb 19 09:56:01 2013] [error]   File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.7.9-py2.6-linux-x86_64.egg/sqlalchemy/orm/query.py", line 2184, in one
[Tue Feb 19 09:56:01 2013] [error]     ret = list(self)
[Tue Feb 19 09:56:01 2013] [error]   File "/usr/local/lib/python2.6/dist-packages/RhodeCode-1.5.2-py2.6.egg/rhodecode/lib/caching_query.py", line 83, in __iter__
[Tue Feb 19 09:56:01 2013] [error]     return Query.__iter__(self)
[Tue Feb 19 09:56:01 2013] [error]   File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.7.9-py2.6-linux-x86_64.egg/sqlalchemy/orm/query.py", line 2226, in __iter__
[Tue Feb 19 09:56:01 2013] [error]     self.session._autoflush()
[Tue Feb 19 09:56:01 2013] [error]   File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.7.9-py2.6-linux-x86_64.egg/sqlalchemy/orm/session.py", line 1120, in _autoflush
[Tue Feb 19 09:56:01 2013] [error]     self.flush()
[Tue Feb 19 09:56:01 2013] [error]   File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.7.9-py2.6-linux-x86_64.egg/sqlalchemy/orm/session.py", line 1718, in flush
[Tue Feb 19 09:56:01 2013] [error]     self._flush(objects)
[Tue Feb 19 09:56:01 2013] [error]   File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.7.9-py2.6-linux-x86_64.egg/sqlalchemy/orm/session.py", line 1789, in _flush
[Tue Feb 19 09:56:01 2013] [error]     flush_context.execute()
[Tue Feb 19 09:56:01 2013] [error]   File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.7.9-py2.6-linux-x86_64.egg/sqlalchemy/orm/unitofwork.py", line 331, in execute
[Tue Feb 19 09:56:01 2013] [error]     rec.execute(self)
[Tue Feb 19 09:56:01 2013] [error]   File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.7.9-py2.6-linux-x86_64.egg/sqlalchemy/orm/unitofwork.py", line 475, in execute
[Tue Feb 19 09:56:01 2013] [error]     uow
[Tue Feb 19 09:56:01 2013] [error]   File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.7.9-py2.6-linux-x86_64.egg/sqlalchemy/orm/persistence.py", line 64, in save_obj
[Tue Feb 19 09:56:01 2013] [error]     table, insert)
[Tue Feb 19 09:56:01 2013] [error]   File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.7.9-py2.6-linux-x86_64.egg/sqlalchemy/orm/persistence.py", line 558, in _emit_insert_statements
[Tue Feb 19 09:56:01 2013] [error]     execute(statement, params)
[Tue Feb 19 09:56:01 2013] [error]   File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.7.9-py2.6-linux-x86_64.egg/sqlalchemy/engine/base.py", line 1449, in execute
[Tue Feb 19 09:56:01 2013] [error]     params)
[Tue Feb 19 09:56:01 2013] [error]   File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.7.9-py2.6-linux-x86_64.egg/sqlalchemy/engine/base.py", line 1584, in _execute_clauseelement
[Tue Feb 19 09:56:01 2013] [error]     compiled_sql, distilled_params
[Tue Feb 19 09:56:01 2013] [error]   File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.7.9-py2.6-linux-x86_64.egg/sqlalchemy/engine/base.py", line 1698, in _execute_context
[Tue Feb 19 09:56:01 2013] [error]     context)
[Tue Feb 19 09:56:01 2013] [error]   File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.7.9-py2.6-linux-x86_64.egg/sqlalchemy/engine/base.py", line 1691, in _execute_context
[Tue Feb 19 09:56:01 2013] [error]     context)
[Tue Feb 19 09:56:01 2013] [error]   File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.7.9-py2.6-linux-x86_64.egg/sqlalchemy/engine/default.py", line 331, in do_execute
[Tue Feb 19 09:56:01 2013] [error]     cursor.execute(statement, parameters)
[Tue Feb 19 09:56:01 2013] [error]   File "/usr/lib/pymodules/python2.6/MySQLdb/cursors.py", line 166, in execute
[Tue Feb 19 09:56:01 2013] [error]     self.errorhandler(self, exc, value)
[Tue Feb 19 09:56:01 2013] [error]   File "/usr/lib/pymodules/python2.6/MySQLdb/connections.py", line 35, in defaulterrorhandler
[Tue Feb 19 09:56:01 2013] [error]     raise errorclass, errorvalue
[Tue Feb 19 09:56:01 2013] [error] IntegrityError: (IntegrityError) (1062, "Duplicate entry '1-3' for key 'users_group_id'") 'INSERT INTO users_group_repo_to_perm (users_group_id, permission_id, repository_id) VALUES (%s, %s, %s)' (1L, 3L, 32L)
[Tue Feb 19 09:56:01 2013] [error] \x1b[0m
[Tue Feb 19 09:56:01 2013] [error] \x1b[0;31m2013-02-19 09:56:01.132 ERROR [rhodecode.controllers.admin.repos] Traceback (most recent call last):
[Tue Feb 19 09:56:01 2013] [error]   File "/usr/local/lib/python2.6/dist-packages/RhodeCode-1.5.2-py2.6.egg/rhodecode/controllers/admin/repos.py", line 240, in update
[Tue Feb 19 09:56:01 2013] [error]     repo = repo_model.update(repo_name, **form_result)
[Tue Feb 19 09:56:01 2013] [error]   File "/usr/local/lib/python2.6/dist-packages/RhodeCode-1.5.2-py2.6.egg/rhodecode/model/repo.py", line 298, in update
[Tue Feb 19 09:56:01 2013] [error]     cur_repo.user = User.get_by_username(kwargs['user'])
[Tue Feb 19 09:56:01 2013] [error]   File "/usr/local/lib/python2.6/dist-packages/RhodeCode-1.5.2-py2.6.egg/rhodecode/model/db.py", line 419, in get_by_username
[Tue Feb 19 09:56:01 2013] [error]     return q.scalar()
[Tue Feb 19 09:56:01 2013] [error]   File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.7.9-py2.6-linux-x86_64.egg/sqlalchemy/orm/query.py", line 2215, in scalar
[Tue Feb 19 09:56:01 2013] [error]     ret = self.one()
[Tue Feb 19 09:56:01 2013] [error]   File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.7.9-py2.6-linux-x86_64.egg/sqlalchemy/orm/query.py", line 2184, in one
[Tue Feb 19 09:56:01 2013] [error]     ret = list(self)
[Tue Feb 19 09:56:01 2013] [error]   File "/usr/local/lib/python2.6/dist-packages/RhodeCode-1.5.2-py2.6.egg/rhodecode/lib/caching_query.py", line 83, in __iter__
[Tue Feb 19 09:56:01 2013] [error]     return Query.__iter__(self)
[Tue Feb 19 09:56:01 2013] [error]   File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.7.9-py2.6-linux-x86_64.egg/sqlalchemy/orm/query.py", line 2226, in __iter__
[Tue Feb 19 09:56:01 2013] [error]     self.session._autoflush()
[Tue Feb 19 09:56:01 2013] [error]   File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.7.9-py2.6-linux-x86_64.egg/sqlalchemy/orm/session.py", line 1120, in _autoflush
[Tue Feb 19 09:56:01 2013] [error]     self.flush()
[Tue Feb 19 09:56:01 2013] [error]   File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.7.9-py2.6-linux-x86_64.egg/sqlalchemy/orm/session.py", line 1718, in flush
[Tue Feb 19 09:56:01 2013] [error]     self._flush(objects)
[Tue Feb 19 09:56:01 2013] [error]   File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.7.9-py2.6-linux-x86_64.egg/sqlalchemy/orm/session.py", line 1789, in _flush
[Tue Feb 19 09:56:01 2013] [error]     flush_context.execute()
[Tue Feb 19 09:56:01 2013] [error]   File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.7.9-py2.6-linux-x86_64.egg/sqlalchemy/orm/unitofwork.py", line 331, in execute
[Tue Feb 19 09:56:01 2013] [error]     rec.execute(self)
[Tue Feb 19 09:56:01 2013] [error]   File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.7.9-py2.6-linux-x86_64.egg/sqlalchemy/orm/unitofwork.py", line 475, in execute
[Tue Feb 19 09:56:01 2013] [error]     uow
[Tue Feb 19 09:56:01 2013] [error]   File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.7.9-py2.6-linux-x86_64.egg/sqlalchemy/orm/persistence.py", line 64, in save_obj
[Tue Feb 19 09:56:01 2013] [error]     table, insert)
[Tue Feb 19 09:56:01 2013] [error]   File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.7.9-py2.6-linux-x86_64.egg/sqlalchemy/orm/persistence.py", line 558, in _emit_insert_statements
[Tue Feb 19 09:56:01 2013] [error]     execute(statement, params)
[Tue Feb 19 09:56:01 2013] [error]   File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.7.9-py2.6-linux-x86_64.egg/sqlalchemy/engine/base.py", line 1449, in execute
[Tue Feb 19 09:56:01 2013] [error]     params)
[Tue Feb 19 09:56:01 2013] [error]   File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.7.9-py2.6-linux-x86_64.egg/sqlalchemy/engine/base.py", line 1584, in _execute_clauseelement
[Tue Feb 19 09:56:01 2013] [error]     compiled_sql, distilled_params
[Tue Feb 19 09:56:01 2013] [error]   File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.7.9-py2.6-linux-x86_64.egg/sqlalchemy/engine/base.py", line 1698, in _execute_context
[Tue Feb 19 09:56:01 2013] [error]     context)
[Tue Feb 19 09:56:01 2013] [error]   File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.7.9-py2.6-linux-x86_64.egg/sqlalchemy/engine/base.py", line 1691, in _execute_context
[Tue Feb 19 09:56:01 2013] [error]     context)
[Tue Feb 19 09:56:01 2013] [error]   File "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.7.9-py2.6-linux-x86_64.egg/sqlalchemy/engine/default.py", line 331, in do_execute
[Tue Feb 19 09:56:01 2013] [error]     cursor.execute(statement, parameters)
[Tue Feb 19 09:56:01 2013] [error]   File "/usr/lib/pymodules/python2.6/MySQLdb/cursors.py", line 166, in execute
[Tue Feb 19 09:56:01 2013] [error]     self.errorhandler(self, exc, value)
[Tue Feb 19 09:56:01 2013] [error]   File "/usr/lib/pymodules/python2.6/MySQLdb/connections.py", line 35, in defaulterrorhandler
[Tue Feb 19 09:56:01 2013] [error]     raise errorclass, errorvalue
[Tue Feb 19 09:56:01 2013] [error] **IntegrityError: (IntegrityError) (1062, "Duplicate entry '1-3' for key 'users_group_id'") 'INSERT INTO users_group_repo_to_perm (users_group_id, permission_id, repository_id) VALUES (%s, %s, %s)' (1L, 3L, 32L)**

I was able to access the database and change the unique constraint on the table users_group_repo_to_perm from (users_group_id, permission_id) to (users_group_id, permission_id, repository_id) manually. Looking at the code of the current version, this should have been done automatically.

I think this issue is very similar to https://bitbucket.org/marcinkuzminski/rhodecode/issue/752/multiple-rows-were-found-for-one

Just putting it out here so if someone has the same problem he can fix it!

Comments (1)

  1. Log in to comment