Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return 409 when creating repo if it already exists. #6330

Conversation

bogdanpetrea
Copy link
Contributor

fixes #6329

@lunny lunny added type/enhancement An improvement of existing functionality modifies/api This PR adds API routes or modifies them labels Mar 14, 2019
@lunny lunny added this to the 1.9.0 milestone Mar 14, 2019
@lafriks lafriks added type/bug and removed type/enhancement An improvement of existing functionality labels Mar 14, 2019
@lafriks lafriks modified the milestones: 1.9.0, 1.8.0 Mar 14, 2019
@lafriks
Copy link
Member

lafriks commented Mar 14, 2019

Moving this to 1.8 as this is more big thant enhancement

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Mar 14, 2019
@bogdanpetrea
Copy link
Contributor Author

It seems that currently the tests fail with a 500 error, because of an uncaught UNIQUE constraint failed: repository.owner_id, repository.lower_name error. Any clue on why it isn't transformed into a ErrRepoAlreadyExist?

@zeripath
Copy link
Contributor

This is likely happening because user id 2's repo2 doesn't actually exist on the filesystem.

If you look at isRepositoryExist():

https://github.com/go-gitea/gitea/blob/master/models/repo.go#L1284

It checks whether the repo is actually extant on the system, and I suspect that repo2 is one of the original test-fixtures so won't have a filesystem representation.

@bogdanpetrea
Copy link
Contributor Author

Thanks for clarifying @zeripath!
Maybe isRepositoryExist could be split into a function with a similar name that checks if the model exists and another isRepositoryReady or similar, that checks if the repo is present on the filesystem. In this way there would be a clear distinction between the 2 situations and the error could be handled better.

@zeripath
Copy link
Contributor

I agree.

@zeripath
Copy link
Contributor

Anyway in this case you should just change your test to actually attempt to create the same repo twice rather than rely on an already "created" repo.

If the provided test environment is too simple for that - copy the style in test_git.go

@bogdanpetrea bogdanpetrea force-pushed the fix-repo-already-exists-incosistency branch 2 times, most recently from 57b1b6b to 4ed74fa Compare March 15, 2019 09:06
@bogdanpetrea bogdanpetrea force-pushed the fix-repo-already-exists-incosistency branch from 4ed74fa to fb69670 Compare March 15, 2019 09:31
@codecov-io
Copy link

codecov-io commented Mar 15, 2019

Codecov Report

Merging #6330 into master will increase coverage by 0.03%.
The diff coverage is 66.66%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #6330      +/-   ##
==========================================
+ Coverage   38.83%   38.86%   +0.03%     
==========================================
  Files         359      359              
  Lines       51182    51183       +1     
==========================================
+ Hits        19875    19892      +17     
+ Misses      28437    28424      -13     
+ Partials     2870     2867       -3
Impacted Files Coverage Δ
routers/api/v1/repo/repo.go 57.08% <66.66%> (+1.7%) ⬆️
models/repo.go 47.44% <0%> (+0.46%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7780ea8...6acc1bb. Read the comment docs.

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Mar 15, 2019
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Mar 15, 2019
@techknowlogick techknowlogick merged commit 583968f into go-gitea:master Mar 15, 2019
@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. modifies/api This PR adds API routes or modifies them type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incosistency when Repo already exists between create/migrate
7 participants