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

Enabling second repository results in: pq: duplicate key value violates unique constraint "UQE_orgs_name" #2092

Closed
5 tasks done
runephilosof-karnovgroup opened this issue Aug 2, 2023 · 3 comments · Fixed by #2104
Labels
bug Something isn't working server
Milestone

Comments

@runephilosof-karnovgroup
Copy link
Contributor

Component

server

Describe the bug

Enabling my first repository worked fine, however the second does not.

When the UI sends a POST request to https://woodpecker-host/api/repos?forge_remote_id=526933511 it returns this error

pq: duplicate key value violates unique constraint "UQE_orgs_name"

The debug log of the server does not give any more insights:

{ip: 10.100.32.116, latency: 474.729763, level: debug, method: POST, path: /api/repos, status: 500, user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36}

System Info

{"source":"https://github.com/woodpecker-ci/woodpecker","version":"1.0.0"}

Additional context

No response

Validations

  • Read the Contributing Guidelines.
  • Read the docs.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • Checked that the bug isn't fixed in the next version already [https://woodpecker-ci.org/faq#which-version-of-woodpecker-should-i-use]
  • Check that this is a concrete bug. For Q&A join our Discord Chat Server or the Matrix room.
@runephilosof-karnovgroup runephilosof-karnovgroup added the bug Something isn't working label Aug 2, 2023
@qwerty287 qwerty287 added this to the 1.0.1 milestone Aug 2, 2023
@lafriks
Copy link
Contributor

lafriks commented Aug 2, 2023

Introduced by #1873

@runephilosof-karnovgroup
Copy link
Contributor Author

This happens because the repo.Owner and the org.Name is not the same.

		woody, err := forge.Org(c, user, "woodpecker-ci")
		log.Debug().Msgf("forge.Org: %v, %v", woody, err)

Outputs

{"level":"debug","time":"2023-08-03T11:44:44+02:00","caller":"/home/runephilosof/code/woodpecker/server/api/repo.go:134","message":"forge.Org: &{0 Woodpecker CI true false}, <nil>"}

So

repo.Owner = "woodpecker-ci"
forge.Org = "Woodpecker CI"

@runephilosof-karnovgroup
Copy link
Contributor Author

runephilosof-karnovgroup commented Aug 3, 2023

We can solve it in github.go:Org() by either using GetLogin() or owner

runephilosof-karnovgroup added a commit to runephilosof-karnovgroup/woodpecker that referenced this issue Aug 3, 2023
For "woodpecker-ci" the `name` is "Woodpecker CI"
 and the `login` is "woodpecker-ci"

Fixes woodpecker-ci#2092

This was causing the organization lookup to fail, because it looks up
using the `login`, when it did not find the organization, it would try
to create it. The creation would fail, because it uses the `name`, and
an organization with that `name` already exists.
Resulting in
```
pq: duplicate key value violates unique constraint "UQE_orgs_name"
```
runephilosof-karnovgroup added a commit to runephilosof-karnovgroup/woodpecker that referenced this issue Aug 3, 2023
`Name` is the human readable name, which could be "Woodpecker CI"
 for the `Path` "woodpecker-ci".
Gitlab supports subgroups, so we need to use the FullPath, otherwise we
would only get `sub-group` when owner is `parent-group/sub-group`.

Fixes woodpecker-ci#2092 when using Gitlab.

This was causing the organization lookup to fail, because it looks up using the `login`, when it did not find the organization, it would try to create it. The creation would fail, because it uses the `name`, and an organization with that `name` already exists.
Resulting in
```
pq: duplicate key value violates unique constraint "UQE_orgs_name"
```
@6543 6543 closed this as completed in #2104 Aug 3, 2023
6543 pushed a commit that referenced this issue Aug 3, 2023
For "woodpecker-ci" the `name` is "Woodpecker CI"
 and the `login` is "woodpecker-ci"

Fixes #2092

This was causing the organization lookup to fail, because it looks up
using the `login`, when it did not find the organization, it would try
to create it. The creation would fail, because it uses the `name`, and
an organization with that `name` already exists.
Resulting in:

```
pq: duplicate key value violates unique constraint "UQE_orgs_name"
```
6543 pushed a commit to 6543-forks/woodpecker that referenced this issue Aug 3, 2023
For "woodpecker-ci" the `name` is "Woodpecker CI"
 and the `login` is "woodpecker-ci"

Fixes woodpecker-ci#2092

This was causing the organization lookup to fail, because it looks up
using the `login`, when it did not find the organization, it would try
to create it. The creation would fail, because it uses the `name`, and
an organization with that `name` already exists.
Resulting in:

```
pq: duplicate key value violates unique constraint "UQE_orgs_name"
```
6543 added a commit that referenced this issue Aug 3, 2023
Backport #2104

For "woodpecker-ci" the `name` is "Woodpecker CI"
 and the `login` is "woodpecker-ci"

Fixes #2092

This was causing the organization lookup to fail, because it looks up
using the `login`, when it did not find the organization, it would try
to create it. The creation would fail, because it uses the `name`, and
an organization with that `name` already exists.
Resulting in:

```
pq: duplicate key value violates unique constraint "UQE_orgs_name"
```

Co-authored-by: runephilosof-karnovgroup <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working server
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants