Group Level Variable API not working as expected

Summary

Group level variables API not working as expected in update operations after introducing environment scope in group level.

Steps to reproduce

  1. create few variables with same name/key and scope it to different environments in group level
  2. try to update any one of the variable

Example Project

What is the current bug behavior?

The update operation takes place with key but when we use several variables with same key and scope it to different environments, it will randomly update the key without filtering it by environment. if we try to update a variable with environment_scope as same it throws error as {'message': {'key': ['(XXXXXXXXX) has already been taken']}} but if we remove the environment_scope, it's randomly updating

What is the expected correct behavior?

Relevant logs and/or screenshots

Output of checks

Results of GitLab environment info

Expand for output related to GitLab environment info

(For installations with omnibus-gitlab package run and paste the output of:
`sudo gitlab-rake gitlab:env:info`)

(For installations from source run and paste the output of:
`sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production`)

Results of GitLab application Check

Expand for output related to the GitLab application check

(For installations with omnibus-gitlab package run and paste the output of: sudo gitlab-rake gitlab:check SANITIZE=true)

(For installations from source run and paste the output of: sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production SANITIZE=true)

(we will only investigate if the tests are passing)

Possible fixes

Edited by Rizwana Abdulla