osbuild: use sort_keys=True when calculating the Context.id

Since we support python3.6 we cannot assume that dicts are ordered
in any way. To ensure the `id` is still always valid we pass
sort_keys=True to json.dump().

Thanks to Simon!
This commit is contained in:
Michael Vogt 2024-03-04 13:03:32 +01:00 committed by Ondřej Budai
parent 87015318d3
commit 27ac6dd544
2 changed files with 7 additions and 6 deletions

View file

@ -99,7 +99,8 @@ class Context:
@property
def id(self):
if self._id is None:
self._id = hashlib.sha256(json.dumps(self._dict()).encode()).hexdigest()
self._id = hashlib.sha256(
json.dumps(self._dict(), sort_keys=True).encode()).hexdigest()
return self._id
def _dict(self):