API repository creation does not work when all subgroups do not yet exist

Issue #117 new
Thomas De Schampheleire created an issue

Kallithea has an API to create a repository, and the help text mentions that if the repository name contains slashes, the corresponding groups would be created automatically.

This does not seem to work. Creating a repo like::

kallithea-api --apikey ****  --apihost ***** create_repo repo_name:foo/bar/repo clone_uri:*********

gives the following log in celery: (not sure if it's celery related)::

IntegrityError: (IntegrityError) insert or update on table "repositories" violates foreign key constraint "repositories_group_id_fkey"
DETAIL:  Key (group_id)=(2) is not present in table "groups".
'INSERT INTO repositories (repo_name, repo_state, clone_uri, repo_type, user_id, private, statistics, downloads, description, created_on, updated_on, landing_revision, enable_locking, locked, changeset_cache, fork_id, group_id) VALUES (%(repo_name)s, %(repo_state)s, %(clone_uri)s, %(repo_type)s, %(user_id)s, %(private)s, %(statistics)s, %(downloads)s, %(description)s, %(created_on)s, %(updated_on)s, %(landing_revision)s, %(enable_locking)s, %(locked)s, %(changeset_cache)s, %(fork_id)s, %(group_id)s) RETURNING repositories.repo_id' {'repo_type': u'hg', 'statistics': False, 'locked': None, 'description': u'repo', 'changeset_cache': None, 'downloads': False, 'private': False, 'clone_uri': u'*****', 'created_on': datetime.datetime(2015, 3, 27, 15, 43, 22, 640922), 'fork_id': None, 'enable_locking': False, 'updated_on': datetime.datetime(2015, 3, 27, 15, 43, 22, 640966), 'user_id': 2, 'landing_revision': 'rev:tip', 'group_id': 2, 'repo_state': 'repo_state_pending', 'repo_name': u'foo/bar/repo'}

Creating the subgroups manually allows the repo creation to work successfully.

Comments (4)

  1. Mads Kiilerich

    I think it would be better if it didn't try to create the "groups" but assumed the parent group already existed. Creating it automatically could be too error prone.

    It should however fail in a better way.

  2. Mads Kiilerich

    I looked at this recently. Creating 'the whole path' is too fragile and undefined. I think we have to make this API require that the folder already exists ... which it apparently kind of already does.

  3. Thomas De Schampheleire reporter

    Code/comments/documentation to be improved: exit gracefully if not all subgroups exist.

  4. Log in to comment