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
This commit is contained in:
adrian-turjak 2016-08-16 10:55:57 +12:00
parent a092d099eb
commit b6316e5965
4 changed files with 25 additions and 2 deletions

1
.gitignore vendored
View File

@ -5,3 +5,4 @@
stacktask.egg-info/*
dist/*
.tox/*
env/*

View File

@ -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),
),
]

View File

@ -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()

View File

@ -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])