improve the consistency of the values stored in consul
Created by: dupainaulevain
This is a followup to the subtle bug fixed a few days ago. It addresses border cases that are unlikely to be an issue right now but may create problems similarly difficult diagnose problems later on.
It would also allow functions that use get to differentiate key containing None from non existent keys. For instance:
modified instance/models/openedx_instance.py
@@ -489,13 +489,13 @@ class OpenEdXInstance(
version_number = agent.get('version') or 0
for key, value in configurations.items():
index, stored_value = agent.get(key, index=True)
- cas = index if stored_value is not None else 0
- agent.put(key, value, cas=cas)
+ if index == '0' or value != stored_value:
+ agent.put(key, value, cas=index)
- if not version_updated and value != stored_value:
- version_updated = True
- version_number += 1
- agent.put('version', version_number)
+ if not version_updated:
+ version_updated = True
+ version_number += 1
+ agent.put('version', version_number)
return version_number, version_updated