From b6316e5965043ecba649b0e96c03d2dd04fd19f6 Mon Sep 17 00:00:00 2001 From: adrian-turjak Date: Tue, 16 Aug 2016 10:55:57 +1200 Subject: [PATCH] Change to fix issues with duplication hash check WARNING: This will involve a minor migration. Fixing the hash value length on the model to be correct. Have made the hash function more sensible, and also not bound to the required field on actions. Needed for how stacktask-odoo handles dynamic required fields. gitignore updated as venv is needed to build migrations easily. Hashing now also properly supports actions with no set serializer. Change-Id: I12f3ad759aaab4c3796e11c359e1ebcbf3ef4e77 --- .gitignore | 1 + .../api/migrations/0002_auto_20160815_2249.py | 19 +++++++++++++++++++ stacktask/api/models.py | 2 +- stacktask/api/v1/utils.py | 5 ++++- 4 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 stacktask/api/migrations/0002_auto_20160815_2249.py diff --git a/.gitignore b/.gitignore index f84b6ab..3a63df7 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ stacktask.egg-info/* dist/* .tox/* +env/* diff --git a/stacktask/api/migrations/0002_auto_20160815_2249.py b/stacktask/api/migrations/0002_auto_20160815_2249.py new file mode 100644 index 0000000..3cd1ba2 --- /dev/null +++ b/stacktask/api/migrations/0002_auto_20160815_2249.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='task', + name='hash_key', + field=models.CharField(max_length=64, db_index=True), + ), + ] diff --git a/stacktask/api/models.py b/stacktask/api/models.py index 4427700..a3e053c 100644 --- a/stacktask/api/models.py +++ b/stacktask/api/models.py @@ -30,7 +30,7 @@ class Task(models.Model): """ uuid = models.CharField(max_length=32, default=hex_uuid, primary_key=True) - hash_key = models.CharField(max_length=32, db_index=True) + hash_key = models.CharField(max_length=64, db_index=True) # who is this: ip_address = models.GenericIPAddressField() diff --git a/stacktask/api/v1/utils.py b/stacktask/api/v1/utils.py index 843df5d..8acbf1b 100644 --- a/stacktask/api/v1/utils.py +++ b/stacktask/api/v1/utils.py @@ -148,8 +148,11 @@ def create_task_hash(task_type, action_list): for action in action_list: hashable_list.append(action['name']) + if not action['serializer']: + continue # iterate like this to maintain consistent order for hash - for field in action['action'].required: + fields = sorted(action['serializer'].validated_data.keys()) + for field in fields: try: hashable_list.append( action['serializer'].validated_data[field])