From e0ae195cfdf163875f660cec86845ee79465abba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Geron?= Date: Thu, 18 Apr 2013 12:19:27 +0200 Subject: [PATCH 1/8] try to debug databag update --- commis/data_bags/views.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/commis/data_bags/views.py b/commis/data_bags/views.py index c9fb27c..d0ac26c 100644 --- a/commis/data_bags/views.py +++ b/commis/data_bags/views.py @@ -49,10 +49,13 @@ def item_get(self, request, bag_name, name): def item_update(self, request, bag_name, name): if not request.json: raise ChefAPIError(500, 'No data sent') - if request.json.get('id') != name: + data = request.json.get('raw_data') + if not isinstance(data, dict): + data = request.json + if not isinstance(request.json, dict) or request.json.get('id') != name: raise ChefAPIError(500, 'Name mismatch in data bag item') item = self.get_item_or_404(bag_name, name) - update(item, data=request.raw_post_data) + update(item, data=json.dumps(data, indent=4)) return HttpResponse(item.data, status=200, content_type='application/json') @api('DELETE', admin=True) From a510f71c78fdd02894fd824c6d8ccb72d67351a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Geron?= Date: Thu, 18 Apr 2013 12:23:04 +0200 Subject: [PATCH 2/8] second try to debug databag update --- commis/data_bags/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commis/data_bags/views.py b/commis/data_bags/views.py index d0ac26c..ce2b747 100644 --- a/commis/data_bags/views.py +++ b/commis/data_bags/views.py @@ -52,7 +52,7 @@ def item_update(self, request, bag_name, name): data = request.json.get('raw_data') if not isinstance(data, dict): data = request.json - if not isinstance(request.json, dict) or request.json.get('id') != name: + if not isinstance(data, dict) or data.get('id') != name: raise ChefAPIError(500, 'Name mismatch in data bag item') item = self.get_item_or_404(bag_name, name) update(item, data=json.dumps(data, indent=4)) From 5fec57031b0a33940b8decb68fed7b3882058af9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Geron?= Date: Thu, 18 Apr 2013 12:27:54 +0200 Subject: [PATCH 3/8] add missing import --- commis/data_bags/views.py | 1 + 1 file changed, 1 insertion(+) diff --git a/commis/data_bags/views.py b/commis/data_bags/views.py index ce2b747..bbef7bd 100644 --- a/commis/data_bags/views.py +++ b/commis/data_bags/views.py @@ -11,6 +11,7 @@ from commis.data_bags.forms import DataBagForm, DataBagItemForm from commis.data_bags.models import DataBag, DataBagItem from commis.db import update +from commis.utils import json class DataBagAPIView(CommisAPIView): model = DataBag From 1944e66ccb6b3a6d901116e1ae3cb0b10be90412 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Geron?= Date: Thu, 18 Apr 2013 18:31:02 +0200 Subject: [PATCH 4/8] add wsgi.py --- commis/wsgi.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 commis/wsgi.py diff --git a/commis/wsgi.py b/commis/wsgi.py new file mode 100644 index 0000000..d4d9653 --- /dev/null +++ b/commis/wsgi.py @@ -0,0 +1,32 @@ +""" +WSGI config for commis project. + +This module contains the WSGI application used by Django's development server +and any production WSGI deployments. It should expose a module-level variable +named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover +this application via the ``WSGI_APPLICATION`` setting. + +Usually you will have the standard Django WSGI application here, but it also +might make sense to replace the whole Django WSGI application with a custom one +that later delegates to the Django one. For example, you could introduce WSGI +middleware here, or combine a Django application with an application of another +framework. + +""" +import os + +# We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks +# if running multiple sites in the same mod_wsgi process. To fix this, use +# mod_wsgi daemon mode with each site in its own daemon process, or use +# os.environ["DJANGO_SETTINGS_MODULE"] = "commis.settings" +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings") + +# This application object is used by any WSGI server configured to use this +# file. This includes Django's development server, if the WSGI_APPLICATION +# setting points here. +from django.core.wsgi import get_wsgi_application +application = get_wsgi_application() + +# Apply WSGI middleware here. +# from helloworld.wsgi import HelloWorldApplication +# application = HelloWorldApplication(application) From 61183d2fc08b9d3e6c467b2616b360513bcfc114 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Geron?= Date: Fri, 19 Apr 2013 10:29:05 +0200 Subject: [PATCH 5/8] fix issue #15: files with identical content in same category ended up having the same path --- commis/cookbooks/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commis/cookbooks/models.py b/commis/cookbooks/models.py index eedbc0a..8132ae1 100644 --- a/commis/cookbooks/models.py +++ b/commis/cookbooks/models.py @@ -36,7 +36,7 @@ def from_dict(self, data): for type, label in CookbookFile.TYPES: for file_info in data.get(type, []): try: - cookbook_file = cookbook.files.get(type=type, file__checksum=file_info['checksum']) + cookbook_file = cookbook.files.get(type=type, name=path=file_info["name"], path=file_info["path"], specificity=file_info["specificity"], file__checksum=file_info['checksum']) except CookbookFile.DoesNotExist: try: file = SandboxFile.objects.get(checksum=file_info['checksum']) From d5b4ecc98860470218a14d578c90baaa7618bee0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Geron?= Date: Fri, 19 Apr 2013 10:29:47 +0200 Subject: [PATCH 6/8] fix issue #15: files with identical content in same category ended up having the same path --- commis/cookbooks/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commis/cookbooks/models.py b/commis/cookbooks/models.py index 8132ae1..136c099 100644 --- a/commis/cookbooks/models.py +++ b/commis/cookbooks/models.py @@ -36,7 +36,7 @@ def from_dict(self, data): for type, label in CookbookFile.TYPES: for file_info in data.get(type, []): try: - cookbook_file = cookbook.files.get(type=type, name=path=file_info["name"], path=file_info["path"], specificity=file_info["specificity"], file__checksum=file_info['checksum']) + cookbook_file = cookbook.files.get(type=type, name=file_info["name"], path=file_info["path"], specificity=file_info["specificity"], file__checksum=file_info['checksum']) except CookbookFile.DoesNotExist: try: file = SandboxFile.objects.get(checksum=file_info['checksum']) From 857f23f485650788f83679fead4d631b6005129f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Geron?= Date: Fri, 19 Apr 2013 10:51:42 +0200 Subject: [PATCH 7/8] do not double cookbook files when uploading an existing cookbook with existing version --- commis/cookbooks/models.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/commis/cookbooks/models.py b/commis/cookbooks/models.py index 136c099..5763c81 100644 --- a/commis/cookbooks/models.py +++ b/commis/cookbooks/models.py @@ -35,18 +35,21 @@ def from_dict(self, data): cookbook.recipes.create(name=name, description=description) for type, label in CookbookFile.TYPES: for file_info in data.get(type, []): + new_content = False try: - cookbook_file = cookbook.files.get(type=type, name=file_info["name"], path=file_info["path"], specificity=file_info["specificity"], file__checksum=file_info['checksum']) + cookbook_file = cookbook.files.get(type=type, path=file_info["path"]) except CookbookFile.DoesNotExist: + cookbook_file = cookbook.files.create(type=type, path=file_info["path"]) + new_content = True + else: + if cookbook_file.file.checksum != file_info["checksum"]: + new_content = True + if new_content: try: - file = SandboxFile.objects.get(checksum=file_info['checksum']) + cookbook_file.file = SandboxFile.objects.get(checksum=file_info['checksum'], uploaded=True) except SandboxFile.DoesNotExist: raise ChefAPIError(500, 'Checksum %s does not match any uploaded file', file_info['checksum']) - if not file.uploaded: - raise ChefAPIError(500, 'Checksum %s does not match any uploaded file', file_info['checksum']) - cookbook_file = cookbook.files.create(type=type, file=file) cookbook_file.name = file_info['name'] - cookbook_file.path = file_info['path'] cookbook_file.specificity = file_info['specificity'] cookbook_file.save() cookbook.save() From a015c734e1d9bb98bf576d1bc2529eda75ac3711 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Geron?= Date: Sat, 20 Apr 2013 23:14:37 +0200 Subject: [PATCH 8/8] remove json indent to avoid wasting space in the database --- commis/data_bags/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commis/data_bags/views.py b/commis/data_bags/views.py index bbef7bd..9b5aac1 100644 --- a/commis/data_bags/views.py +++ b/commis/data_bags/views.py @@ -56,7 +56,7 @@ def item_update(self, request, bag_name, name): if not isinstance(data, dict) or data.get('id') != name: raise ChefAPIError(500, 'Name mismatch in data bag item') item = self.get_item_or_404(bag_name, name) - update(item, data=json.dumps(data, indent=4)) + update(item, data=json.dumps(data)) return HttpResponse(item.data, status=200, content_type='application/json') @api('DELETE', admin=True)