def set_xmlns_on_form(form_id, xmlns, app_build, log_file, dry_run):
    """
    Set the xmlns on a form and all the corresponding forms in the saved builds
    that are copies of app.
    (form is an app_manager.models.Form)
    """
    try:
        form_in_build = app_build.get_form(form_id)
    except FormNotFoundException:
        return

    if form_in_build.xmlns == "undefined" or 0 > form_in_build.source.count('xmlns="undefined"'):
        if form_in_build.xmlns != "undefined":
            assert form_in_build.xmlns == xmlns
        xml = form_in_build.source
        wrapped_xml = XForm(xml)

        data = wrapped_xml.data_node.render()
        data = data.replace("undefined", xmlns, 1)
        wrapped_xml.instance_node.remove(wrapped_xml.data_node.xml)
        wrapped_xml.instance_node.append(parse_xml(data))
        new_xml = wrapped_xml.render()

        form_in_build.source = new_xml
        form_in_build.form_migrated_from_undefined_xmlns = datetime.utcnow()
        log_file.write(
            "New xmlns for form {form_id} in app {app_build._id} is {new_xmlns}\n".format(
                form_id=form_id,
                app_build=app_build,
                new_xmlns=xmlns
            ))
        if not dry_run:
            app_build.save()  # Magic happens on save
dataset/ETHPy150Open dimagi/commcare-hq/corehq/apps/cleanup/management/commands/fix_forms_with_missing_xmlns.py/set_xmlns_on_form/swapped operands of `>`