From 5523c2883eefd66d3b455d87fca5b411e0219d86 Mon Sep 17 00:00:00 2001 From: Victor Shnayder Date: Mon, 6 Aug 2012 11:14:59 -0400 Subject: [PATCH] Generate error module url_names using sha1 * means we get the same url_name on each import of the same data. --- common/lib/xmodule/xmodule/error_module.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/common/lib/xmodule/xmodule/error_module.py b/common/lib/xmodule/xmodule/error_module.py index cbd805396f..882d181b8b 100644 --- a/common/lib/xmodule/xmodule/error_module.py +++ b/common/lib/xmodule/xmodule/error_module.py @@ -1,3 +1,4 @@ +import hashlib import logging import random import string @@ -48,13 +49,12 @@ class ErrorDescriptor(EditingDescriptor): definition = {'data': inner} inner['error_msg'] = str(error_msg) - # Pick a unique (random) url_name. + # Pick a unique url_name -- the sha1 hash of the xml_data. # NOTE: We could try to pull out the url_name of the errored descriptor, # but url_names aren't guaranteed to be unique between descriptor types, # and ErrorDescriptor can wrap any type. When the wrapped module is fixed, # it will be written out with the original url_name. - chars = string.ascii_uppercase + string.ascii_lowercase + string.digits - url_name = ''.join(random.choice(chars) for i in range(16)) + url_name = hashlib.sha1(xml_data).hexdigest() try: # If this is already an error tag, don't want to re-wrap it.