From 89ade49695c8961f23879050dda8aa684603c04b Mon Sep 17 00:00:00 2001 From: Kevin Chung Date: Mon, 27 Apr 2020 01:49:56 -0400 Subject: [PATCH] Fix serializer --- CTFd/utils/exports/serializers.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CTFd/utils/exports/serializers.py b/CTFd/utils/exports/serializers.py index 5158097..de161f2 100644 --- a/CTFd/utils/exports/serializers.py +++ b/CTFd/utils/exports/serializers.py @@ -1,6 +1,6 @@ import json import six -from collections import OrderedDict +from collections import defaultdict, OrderedDict from CTFd.utils.exports.encoders import JSONEncoder @@ -9,7 +9,7 @@ class JSONSerializer(object): def __init__(self, query, fileobj): self.query = query self.fileobj = fileobj - self.buckets = [] + self.buckets = defaultdict(list) def serialize(self): for row in self.query: @@ -17,7 +17,7 @@ class JSONSerializer(object): self.close() def write(self, path, result): - self.buckets.append([result]) + self.buckets[path].append(result) def wrap(self, result): result = OrderedDict([("count", len(result)), ("results", result)]) @@ -25,7 +25,7 @@ class JSONSerializer(object): return result def close(self): - for result in self.buckets: + for path, result in self.buckets.items(): result = self.wrap(result) # Certain databases (MariaDB) store JSON as LONGTEXT.