Merge "Strip id/uid from .json input"

This commit is contained in:
Zuul 2022-06-30 00:35:31 +00:00 committed by Gerrit Code Review
commit c1b6f9f4d2
3 changed files with 11 additions and 1 deletions

View File

@ -56,6 +56,13 @@ class YamlParser(object):
slug = slugify(data['title'])
if not self.data.get('dashboard'):
self.data['dashboard'] = {}
# The idea is that people work interactively locally using
# the GUI editor, then export the .json using the sharing
# panel. That mostly works, but it can leave a id & uid
# that isn't valid when importing to another grafana
# instance. Remove them.
data.pop('id', None)
data.pop('uid', None)
self.data['dashboard'][slug] = data
else:
result = self.validate(data)

View File

@ -137,5 +137,6 @@
"timezone": "",
"title": "test json",
"uid": "M-GEcyWMk",
"version": 1
"version": 1,
"id": 1234
}

View File

@ -109,3 +109,5 @@ class TestCaseParser(TestCase):
# Get parsed dashboard
res, md5 = self.parser.get_dashboard('test-json')
self.assertEqual(res['title'], 'test json')
self.assertNotIn('id', res.keys())
self.assertNotIn('uid', res.keys())