Open link in a new tab

Content

Expand project menu

api & /api/v3/projects/{id}/copy endpoint & project_statuses_pkey

Hi,

I am using

OpenProject 12.3.3 

PostgreSQL version 13.7

When I try to use the api to copy a project to create a new one I get this error:

( where my endpoint is /api/v3/projects/23/copy as 23 is the id of template I am trying to use and in the header I just have the name of the new project)

2022-11-23 16:00:52.927 UTC [38] ERROR:  duplicate key value violates unique constraint "project_statuses_pkey"

2022-11-23 16:00:52.927 UTC [38] DETAIL:  Key (id)=(23) already exists.

2022-11-23 16:00:52.927 UTC [38] STATEMENT:  INSERT INTO "project_statuses" ("id", "project_id", "explanation", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5) RETURNING "id"

Is this a bug or am I doing something wrong ?

Message actions

Hey,

The sentence: please share your APIv3 call in your code

'I try to use the api to copy a project to create a new one' is not an APIv3 syntax :)

I cannot answer your question if I do not see the APIv3 call

Message actions

Yes apologies !

When I try by an API call to create a copy of a project, I get this error:

....

Here is my api call, it very simple. the error is in my db log

auth = HTTPBasicAuth('apikey', ‘xxxxxxx’)
ServerIP = ‘X.X.X.X’
IDTemplate = ’34’

def create_project(CustumerID,CustumerName):
    print(f'create Project {ProjectID} with {ProjectName}')
    url_cr = f'https://{ServerIP}/api/v3/projects/{IDTemplate}/copy'
    json_cr = {'name': ProjectName, 'customField9': ProjectID}
    cr = requests.post(url_cr, json=json_cr, auth=auth, verify=False)
    ....
    pprint(cr.json())
    ...
Message actions

If I try with a different project I have the same problem

Url endpoint: /api/v3/projects/139/copy

Same payload json {'name': 'test', 'customField9': 'test'}

logs db:

2022-11-29 13:56:23.817 UTC [38] ERROR:  duplicate key value violates unique constraint "project_statuses_pkey"

2022-11-29 13:56:23.817 UTC [38] DETAIL:  Key (id)=(93) already exists.

2022-11-29 13:56:23.817 UTC [38] STATEMENT:  INSERT INTO "project_statuses" ("id", "project_id", "explanation", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5) RETURNING "id"

with in the db:

openproject=# SELECT * FROM project_statuses where project_id=139;
id | project_id | explanation | code |          created_at           |          updated_at        
----+------------+-------------+------+-------------------------------+-------------------------------
93 |        139 |             |      | 2022-11-29 13:52:24.923032+00 | 2022-11-29 13:52:24.923032+00