Error when importing library to Lilac via manage.py cms import_content_library

When I run

tutor local run -v /home/ubuntu/all_libs:/tmp/bla cms ./manage.py cms import_content_library /tmp/bla/library-v1+MyOrg+MyLibrary.tar.gz Admin

It works for the vast majority of libraries I’m moving between systems (from Nutmeg to Lilac). However, for 4/50 libraries, I get an error like the below: (tldr: "raise source.error("missing ), unterminated subpattern"," )

Has anyone experienced this before, and know how to get around it?

2023-03-17 17:29:43,758 ERROR 1 [xmodule.modulestore.xml] [user None] [ip None] xml.py:380 - Course import library-v1:MyOrg+MyLibrary: ERROR: Failed to load courselike "bGlicmFyeS12MStPcGVuU2VjdXJpdHlUcmFpbmluZzIrVnVsbnMxMDAxX0JyYWluX0Jvb3N0X0FmdGVyX09PQlcudGFyLmd6/library": missing ), unterminated subpattern at position 98 (line 6, column 14)
Traceback (most recent call last):
  File "/openedx/edx-platform/common/lib/xmodule/xmodule/modulestore/xml.py", line 377, in try_load_course
    course_descriptor = self.load_course(course_dir, course_ids, errorlog.tracker, target_course_id)
  File "/openedx/edx-platform/common/lib/xmodule/xmodule/modulestore/xml.py", line 525, in load_course
    course_descriptor = system.process_xml(etree.tostring(course_data, encoding='unicode'))
  File "/openedx/edx-platform/common/lib/xmodule/xmodule/modulestore/xml.py", line 167, in process_xml
    descriptor = self.xblock_from_node(
  File "/openedx/edx-platform/common/lib/xmodule/xmodule/x_module.py", line 1680, in xblock_from_node
    block = block_class.parse_xml(node, self, keys, id_generator)
  File "/openedx/venv/lib/python3.8/site-packages/xblock/mixins.py", line 460, in parse_xml
    block.runtime.add_node_as_child(block, child, id_generator)
  File "/openedx/edx-platform/common/lib/xmodule/xmodule/modulestore/xml.py", line 249, in add_node_as_child
    child_block = self.process_xml(etree.tostring(node))
  File "/openedx/edx-platform/common/lib/xmodule/xmodule/modulestore/xml.py", line 167, in process_xml
    descriptor = self.xblock_from_node(
  File "/openedx/edx-platform/common/lib/xmodule/xmodule/x_module.py", line 1680, in xblock_from_node
    block = block_class.parse_xml(node, self, keys, id_generator)
  File "/openedx/edx-platform/common/lib/xmodule/xmodule/xml_module.py", line 572, in parse_xml
    return super(XmlParserMixin, cls).parse_xml(node, runtime, keys, id_generator)  # pylint: disable=bad-super-call
  File "/openedx/edx-platform/common/lib/xmodule/xmodule/x_module.py", line 1123, in parse_xml
    block = cls.from_xml(xml, runtime, id_generator)
  File "/openedx/edx-platform/common/lib/xmodule/xmodule/xml_module.py", line 557, in from_xml
    return super().parse_xml(
  File "/openedx/edx-platform/common/lib/xmodule/xmodule/xml_module.py", line 349, in parse_xml
    definition, children = cls.load_definition(definition_xml, runtime, def_id, id_generator)
  File "/openedx/edx-platform/common/lib/xmodule/xmodule/xml_module.py", line 265, in load_definition
    definition, children = cls.definition_from_xml(definition_xml, system)
  File "/openedx/edx-platform/common/lib/xmodule/xmodule/raw_module.py", line 37, in definition_from_xml
    data = re.sub(match.group(), pre_tag_data[match_num].decode(), data)
  File "/opt/pyenv/versions/3.8.6/lib/python3.8/re.py", line 210, in sub
    return _compile(pattern, flags).sub(repl, string, count)
  File "/opt/pyenv/versions/3.8.6/lib/python3.8/re.py", line 304, in _compile
    p = sre_compile.compile(pattern, flags)
  File "/opt/pyenv/versions/3.8.6/lib/python3.8/sre_compile.py", line 764, in compile
    p = sre_parse.parse(p, flags)
  File "/opt/pyenv/versions/3.8.6/lib/python3.8/sre_parse.py", line 948, in parse
    p = _parse_sub(source, state, flags & SRE_FLAG_VERBOSE, 0)
  File "/opt/pyenv/versions/3.8.6/lib/python3.8/sre_parse.py", line 443, in _parse_sub
    itemsappend(_parse(source, state, verbose, nested + 1,
  File "/opt/pyenv/versions/3.8.6/lib/python3.8/sre_parse.py", line 836, in _parse
    raise source.error("missing ), unterminated subpattern",
re.error: missing ), unterminated subpattern at position 98 (line 6, column 14)

=== Failed to import library-v1:MyOrg+MyLibrary
Traceback (most recent call last):
  File "./manage.py", line 123, in <module>
    execute_from_command_line([sys.argv[0]] + django_args)
  File "/openedx/venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "/openedx/venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/openedx/venv/lib/python3.8/site-packages/django/core/management/base.py", line 323, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/openedx/venv/lib/python3.8/site-packages/django/core/management/base.py", line 364, in execute
    output = self.handle(*args, **options)
  File "/openedx/edx-platform/cms/djangoapps/contentstore/management/commands/import_content_library.py", line 87, in handle
    import_library_from_xml(
  File "/openedx/edx-platform/common/lib/xmodule/xmodule/modulestore/xml_importer.py", line 769, in import_library_from_xml
    manager = LibraryImportManager(*args, **kwargs)
  File "/openedx/edx-platform/common/lib/xmodule/xmodule/modulestore/xml_importer.py", line 253, in __init__
    self.xml_module_store = self.store_class(
  File "/openedx/edx-platform/common/lib/xmodule/xmodule/modulestore/xml.py", line 363, in __init__
    self.try_load_course(course_dir, course_ids, target_course_id)
  File "/openedx/edx-platform/common/lib/xmodule/xmodule/modulestore/xml.py", line 384, in try_load_course
    raise exc
  File "/openedx/edx-platform/common/lib/xmodule/xmodule/modulestore/xml.py", line 377, in try_load_course
    course_descriptor = self.load_course(course_dir, course_ids, errorlog.tracker, target_course_id)
  File "/openedx/edx-platform/common/lib/xmodule/xmodule/modulestore/xml.py", line 525, in load_course
    course_descriptor = system.process_xml(etree.tostring(course_data, encoding='unicode'))
  File "/openedx/edx-platform/common/lib/xmodule/xmodule/modulestore/xml.py", line 167, in process_xml
    descriptor = self.xblock_from_node(
  File "/openedx/edx-platform/common/lib/xmodule/xmodule/x_module.py", line 1680, in xblock_from_node
    block = block_class.parse_xml(node, self, keys, id_generator)
  File "/openedx/venv/lib/python3.8/site-packages/xblock/mixins.py", line 460, in parse_xml
    block.runtime.add_node_as_child(block, child, id_generator)
  File "/openedx/edx-platform/common/lib/xmodule/xmodule/modulestore/xml.py", line 249, in add_node_as_child
    child_block = self.process_xml(etree.tostring(node))
  File "/openedx/edx-platform/common/lib/xmodule/xmodule/modulestore/xml.py", line 167, in process_xml
    descriptor = self.xblock_from_node(
  File "/openedx/edx-platform/common/lib/xmodule/xmodule/x_module.py", line 1680, in xblock_from_node
    block = block_class.parse_xml(node, self, keys, id_generator)
  File "/openedx/edx-platform/common/lib/xmodule/xmodule/xml_module.py", line 572, in parse_xml
    return super(XmlParserMixin, cls).parse_xml(node, runtime, keys, id_generator)  # pylint: disable=bad-super-call
  File "/openedx/edx-platform/common/lib/xmodule/xmodule/x_module.py", line 1123, in parse_xml
    block = cls.from_xml(xml, runtime, id_generator)
  File "/openedx/edx-platform/common/lib/xmodule/xmodule/xml_module.py", line 557, in from_xml
    return super().parse_xml(
  File "/openedx/edx-platform/common/lib/xmodule/xmodule/xml_module.py", line 349, in parse_xml
    definition, children = cls.load_definition(definition_xml, runtime, def_id, id_generator)
  File "/openedx/edx-platform/common/lib/xmodule/xmodule/xml_module.py", line 265, in load_definition
    definition, children = cls.definition_from_xml(definition_xml, system)
  File "/openedx/edx-platform/common/lib/xmodule/xmodule/raw_module.py", line 37, in definition_from_xml
    data = re.sub(match.group(), pre_tag_data[match_num].decode(), data)
  File "/opt/pyenv/versions/3.8.6/lib/python3.8/re.py", line 210, in sub
    return _compile(pattern, flags).sub(repl, string, count)
  File "/opt/pyenv/versions/3.8.6/lib/python3.8/re.py", line 304, in _compile
    p = sre_compile.compile(pattern, flags)
  File "/opt/pyenv/versions/3.8.6/lib/python3.8/sre_compile.py", line 764, in compile
    p = sre_parse.parse(p, flags)
  File "/opt/pyenv/versions/3.8.6/lib/python3.8/sre_parse.py", line 948, in parse
    p = _parse_sub(source, state, flags & SRE_FLAG_VERBOSE, 0)
  File "/opt/pyenv/versions/3.8.6/lib/python3.8/sre_parse.py", line 443, in _parse_sub
    itemsappend(_parse(source, state, verbose, nested + 1,
  File "/opt/pyenv/versions/3.8.6/lib/python3.8/sre_parse.py", line 836, in _parse
    raise source.error("missing ), unterminated subpattern",
re.error: missing ), unterminated subpattern at position 98 (line 6, column 14)
ERROR: 1
Error: Command failed with status 1: docker-compose -f /home/ubuntu/.local/share/tutor/env/local/docker-compose.yml -f /home/ubuntu/.local/share/tutor/env/local/docker-compose.prod.yml --project-name tutor_local run --volume /home/ubuntu/all_libs:/tmp/bla --rm cms ./manage.py cms import_content_library /tmp/bla/library-v1+MyOrg+MyLibrary.tar.gz Admin

This turned out to be due to the presence of <code> tags, within some questions that were written in advanced mode. They worked perfectly fine in the original Open edX instance, it’s just the library import chokes on them.

Where should this bug be filed?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.