diff --git a/lti_consumer/migrations/0010_backfill-empty-string-lti-config.py b/lti_consumer/migrations/0010_backfill-empty-string-lti-config.py new file mode 100644 index 0000000000000000000000000000000000000000..a3773d7465a8f5f41f4ff67d821f4c0845837b91 --- /dev/null +++ b/lti_consumer/migrations/0010_backfill-empty-string-lti-config.py @@ -0,0 +1,68 @@ +""" +Backfill empty lti_config records + +We need to do this with raw SQL, +otherwise the model fails upon instantiation, +as the empty string is an invalid JSON dictionary. +""" +import uuid + +from django.db import connection +from django.db import migrations + + +sql_forward = """\ +UPDATE + lti_consumer_lticonfiguration +SET + lti_config = %s +WHERE + id = %s +;\ +""" + +sql_select_empty = """\ +SELECT + id +FROM + lti_consumer_lticonfiguration +WHERE + lti_config = "" +;\ +""" + + +def _get_ids_with_empty_lti_config(): + """ + Retrieve the list of primary keys for each entry with a blank lti_config + """ + with connection.cursor() as cursor: + cursor.execute(sql_select_empty) + for row in cursor.fetchall(): + yield row[0] + + +def _forward(apps, schema_editor): + """ + Generate an empty JSON dict for rows missing one + """ + for _id in _get_ids_with_empty_lti_config(): + lti_config = '{}' + schema_editor.execute(sql_forward, [ + lti_config, + _id, + ]) + + +class Migration(migrations.Migration): + """ + Backfill empty lti_config records + """ + + dependencies = [ + ('lti_consumer', '0009_backfill-empty-string-config-id'), + ] + + operations = [ + migrations.RunPython(_forward, atomic=False), + ] diff --git a/setup.py b/setup.py index 890c2922fed88c2dda9552c92de89660cb341495..68b15fbad4537f89acd4c5220cd95f4754fa21c3 100644 --- a/setup.py +++ b/setup.py @@ -49,7 +49,7 @@ with open('README.rst') as _f: setup( name='lti-consumer-xblock', - version='2.7.0', + version='2.7.1', description='This XBlock implements the consumer side of the LTI specification.', long_description=long_description, long_description_content_type='text/x-rst',