<commit_before>{% macro testconn() %}
  <script>
    $("#sqlalchemy_uri").parent()
      .append('<button id="testconn" class="btn">{{ _("Test Connection") }}</button>');
    $("#testconn").click(function(e) {
      e.preventDefault();
      var url = "/superset/testconn";
      var csrf_token = "{{ csrf_token() }}";

      $.ajaxSetup({
        beforeSend: function(xhr, settings) {
          if (!/^(GET|HEAD|OPTIONS|TRACE)$/i.test(settings.type) && !this.crossDomain) {
            xhr.setRequestHeader("X-CSRFToken", csrf_token);
          }
        }
      });

      var data = {};
      try{
        data = JSON.stringify({
          uri: $("#sqlalchemy_uri").val(),
          name: $('#database_name').val(),
          extras: JSON.parse($("#extra").val()),
        })
      } catch(parse_error){
        alert("Malformed JSON in the extras field: " + parse_error);
        return false
      }

      $.ajax({
        method: "POST",<commit_msg>[bugfix] allow database macro to work when CSRF is diabled (#2884)<commit_after>{% macro testconn() %}
  <script>
    $("#sqlalchemy_uri").parent()
      .append('<button id="testconn" class="btn">{{ _("Test Connection") }}</button>');
    $("#testconn").click(function(e) {
      e.preventDefault();
      var url = "/superset/testconn";
      var csrf_token = "{{ csrf_token() if csrf_token else '' }}";

      $.ajaxSetup({
        beforeSend: function(xhr, settings) {
          if (!/^(GET|HEAD|OPTIONS|TRACE)$/i.test(settings.type) && !this.crossDomain) {
            xhr.setRequestHeader("X-CSRFToken", csrf_token);
          }
        }
      });

      var data = {};
      try{
        data = JSON.stringify({
          uri: $("#sqlalchemy_uri").val(),
          name: $('#database_name').val(),
          extras: JSON.parse($("#extra").val()),
        })
      } catch(parse_error){
        alert("Malformed JSON in the extras field: " + parse_error);
        return false
      }

      $.ajax({
        method: "POST",
{'fraction_non_alphanumeric': 0.19073980875691998, 'fraction_numerical': 0.0020130850528434826, 'mean_word_length': 2.3524451939291735, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '10725', 'n_tokens_mistral': 624, 'n_tokens_neox': 619, 'n_words': 116}