Grafana 5.4.2 can't create datasource with same name in different orgs

api

#1

Hello,

I’ve been using the grafana api extensively to create organisations and datasources within organisations.
I’m doing all of this via some automation scripts.
I tried to switch from Grafana 5.2.3 to 5.4.2 today and my automation still configures Grafana the same way (adding organisations and datasources).
However with 5.4.2 one can not add multiple datasources with the same name into different organisations.
The API returns “datasource already exists”

I’d consider this a bug or is there any reason why this is not possible anymore?

I used to create a influxdb datasource named “dt” to every organisation, after switching the active users context to that organisation:

apiurl = grafana + "/api/datasources"
headers = {'Content-type': 'application/json'}
jsondata = '{ \
    "Name":"dt", \
    "Type":"influxdb", \
    "url":"' + influxdburl + '", \
    "database": "' + influxdb + '", \
    "password":"' + influxdbpwd + '", \
    "user":"' + influxdbuser + '", \
    "Access":"proxy", \
    "basicAuth":false, \
    "isDefault" : true, \
    "jsonData":{ \
        "keepCookies":[], \
        "timeInterval":"1m" \
        } \
    }'

switchOrganisation(grafanauser,orgid)
response = session.post(apiurl, data=jsondata, headers=headers, timeout=5, verify=False)
if response.status_code == 200:
    print("Datasource added: {}".format(influxdb))
else:
    print("Couldn't add datasource {} - {}".format(influxdb,response.json()['message']))
    id = getDatasourceId('dt')
    print("Attempting to update Datasource ID:{}".format(id))
    updateDatasource(influxdb, id, orgid)
return

#2

Tessted also with 5.3.4, works perfectly there. So this seems to be some kind of regression starting with 5.4.0