saml: use get_or_create() in save_key_values (fixes #6883)

With a simple Model.save() the second save in case of replay fails
because the created is updated to the NULL value. It seem that
initialization of DateTime field is ignored when Django detects that a
save is an UPDATE and not an INSERT.
This commit is contained in:
Benjamin Dauvergne 2015-04-01 18:01:37 +02:00
parent 5d6723ad00
commit 6491033c80
1 changed files with 5 additions and 1 deletions

View File

@ -819,7 +819,11 @@ class KeyValue(models.Model):
verbose_name_plural = _("key value associations")
def save_key_values(key, *values):
KeyValue(key = key, value = values).save()
# never update an existing key, key are nonces
kv, created = KeyValue.objects.get_or_create(key=key, defaults={'value': values})
if not created:
kv.value = values
kv.save()
def get_and_delete_key_values(key):
try: