From b9c916a4be417c58dd13e84240237570c06aa665 Mon Sep 17 00:00:00 2001
From: Cedric Bosdonnat <cedric.bosdonnat@free.fr>
Date: Fri, 24 Sep 2021 17:02:05 +0200
Subject: [PATCH] 3002.2 - postgresql JSON support in pillar (#424)

* Allow single field returns from SQL pillar

Several SQL databases support native JSON storage. When storing
pillars in this way, SQL query result already returns dict and
without the need to have key column.

* Add and adapt tests for as_json sql mode

* Add missing entries to rest of sql pillar tests

* Add changelog entry

* Fix the sql_base pillar merge for as_json

Use salt.utils.update() to recursively merge the JSON dicts of the
returned SQL queries.

Co-authored-by: Ondrej Holecek <oholecek@suse.com>
---
 changelog/60905.added                      |  1 +
 salt/pillar/sql_base.py                    | 38 +++++++++++++++
 tests/pytests/unit/pillar/test_sql_base.py | 43 ++++++++++++++++
 tests/unit/pillar/test_mysql.py            | 57 ++++++++++++++++++++++
 tests/unit/pillar/test_sqlcipher.py        | 32 ++++++++++++
 tests/unit/pillar/test_sqlite3.py          | 32 ++++++++++++
 6 files changed, 203 insertions(+)
 create mode 100644 changelog/60905.added
 create mode 100644 tests/pytests/unit/pillar/test_sql_base.py

diff --git a/changelog/60905.added b/changelog/60905.added
new file mode 100644
index 0000000000..3fe39286a8
--- /dev/null
+++ b/changelog/60905.added
@@ -0,0 +1 @@
+Support querying for JSON data in SQL external pillar
diff --git a/salt/pillar/sql_base.py b/salt/pillar/sql_base.py
index 976ca8c0d8..9d9f0c9c9f 100644
--- a/salt/pillar/sql_base.py
+++ b/salt/pillar/sql_base.py
@@ -137,6 +137,33 @@ These columns define list grouping
 The range for with_lists is 1 to number_of_fields, inclusive.
 Numbers outside this range are ignored.
 
+If you specify `as_json: True` in the mapping expression and query only for
+single value, returned data are considered in JSON format and will be merged
+directly.
+
+.. code-block:: yaml
+
+  ext_pillar:
+    - sql_base:
+        - query: "SELECT json_pillar FROM pillars WHERE minion_id = %s"
+          as_json: True
+
+The processed JSON entries are recursively merged in a single dictionary.
+Additionnaly if `as_list` is set to `True` the lists will be merged in case of collision.
+
+For instance the following rows:
+
+    {"a": {"b": [1, 2]}, "c": 3}
+    {"a": {"b": [1, 3]}, "d": 4}
+
+will result in the following pillar with `as_list=False`
+
+    {"a": {"b": [1, 3], "c": 3, "d": 4}
+
+and in with `as_list=True`
+
+    {"a": {"b": [1, 2, 3], "c": 3, "d": 4}
+
 Finally, if you pass the queries in via a mapping, the key will be the
 first level name where as passing them in as a list will place them in the
 root.  This isolates the query results into their own subtrees.
@@ -179,6 +206,7 @@ from salt.ext import six
 from salt.ext.six.moves import range
 
 # Import Salt libs
+from salt.utils.dictupdate import update
 from salt.utils.odict import OrderedDict
 
 # Please don't strip redundant parentheses from this file.
@@ -208,6 +236,7 @@ class SqlBaseExtPillar(six.with_metaclass(abc.ABCMeta, object)):
     num_fields = 0
     depth = 0
     as_list = False
+    as_json = False
     with_lists = None
     ignore_null = False
 
@@ -267,6 +296,7 @@ class SqlBaseExtPillar(six.with_metaclass(abc.ABCMeta, object)):
                 "query": "",
                 "depth": 0,
                 "as_list": False,
+                "as_json": False,
                 "with_lists": None,
                 "ignore_null": False,
             }
@@ -324,6 +354,13 @@ class SqlBaseExtPillar(six.with_metaclass(abc.ABCMeta, object)):
         for ret in rows:
             # crd is the Current Return Data level, to make this non-recursive.
             crd = self.focus
+
+            # We have just one field without any key, assume returned row is already a dict
+            # aka JSON storage
+            if self.as_json and self.num_fields == 1:
+                crd = update(crd, ret[0], merge_lists=self.as_list)
+                continue
+
             # Walk and create dicts above the final layer
             for i in range(0, self.depth - 1):
                 # At the end we'll use listify to find values to make a list of
@@ -443,6 +480,7 @@ class SqlBaseExtPillar(six.with_metaclass(abc.ABCMeta, object)):
                 )
                 self.enter_root(root)
                 self.as_list = details["as_list"]
+                self.as_json = details["as_json"]
                 if details["with_lists"]:
                     self.with_lists = details["with_lists"]
                 else:
diff --git a/tests/pytests/unit/pillar/test_sql_base.py b/tests/pytests/unit/pillar/test_sql_base.py
new file mode 100644
index 0000000000..0d44c2d608
--- /dev/null
+++ b/tests/pytests/unit/pillar/test_sql_base.py
@@ -0,0 +1,43 @@
+import pytest
+import salt.pillar.sql_base as sql_base
+from tests.support.mock import MagicMock
+
+
+class FakeExtPillar(sql_base.SqlBaseExtPillar):
+    """
+    Mock SqlBaseExtPillar implementation for testing purpose
+    """
+
+    @classmethod
+    def _db_name(cls):
+        return "fake"
+
+    def _get_cursor(self):
+        return MagicMock()
+
+
+@pytest.mark.parametrize("as_list", [True, False])
+def test_process_results_as_json(as_list):
+    """
+    Validates merging of dict values returned from JSON datatype.
+    """
+    return_data = FakeExtPillar()
+    return_data.as_list = as_list
+    return_data.as_json = True
+    return_data.with_lists = None
+    return_data.enter_root(None)
+    return_data.process_fields(["json_data"], 0)
+    test_dicts = [
+        ({"a": [1]},),
+        ({"b": [2, 3]},),
+        ({"a": [4]},),
+        ({"c": {"d": [4, 5], "e": 6}},),
+        ({"f": [{"g": 7, "h": "test"}], "c": {"g": 8}},),
+    ]
+    return_data.process_results(test_dicts)
+    assert return_data.result == {
+        "a": [1, 4] if as_list else [4],
+        "b": [2, 3],
+        "c": {"d": [4, 5], "e": 6, "g": 8},
+        "f": [{"g": 7, "h": "test"}],
+    }
diff --git a/tests/unit/pillar/test_mysql.py b/tests/unit/pillar/test_mysql.py
index bc81eb4174..9db724329d 100644
--- a/tests/unit/pillar/test_mysql.py
+++ b/tests/unit/pillar/test_mysql.py
@@ -26,6 +26,7 @@ class MysqlPillarTestCase(TestCase):
                         "query": "SELECT blah",
                         "depth": 0,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -47,6 +48,7 @@ class MysqlPillarTestCase(TestCase):
                 {"query": "SELECT blah7", "as_list": True},
                 {"query": "SELECT blah8", "with_lists": "1"},
                 {"query": "SELECT blah9", "with_lists": "1,2"},
+                {"query": "SELECT json1", "as_json": True},
             ],
             {},
         )
@@ -59,6 +61,7 @@ class MysqlPillarTestCase(TestCase):
                         "query": "SELECT blah",
                         "depth": 0,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -69,6 +72,7 @@ class MysqlPillarTestCase(TestCase):
                         "query": "SELECT blah2",
                         "depth": 0,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -79,6 +83,7 @@ class MysqlPillarTestCase(TestCase):
                         "query": "SELECT blah3",
                         "depth": 0,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -89,6 +94,7 @@ class MysqlPillarTestCase(TestCase):
                         "query": "SELECT blah4",
                         "depth": 2,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -99,6 +105,7 @@ class MysqlPillarTestCase(TestCase):
                         "query": "SELECT blah5",
                         "depth": 0,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -109,6 +116,7 @@ class MysqlPillarTestCase(TestCase):
                         "query": "SELECT blah6",
                         "depth": 2,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -119,6 +127,7 @@ class MysqlPillarTestCase(TestCase):
                         "query": "SELECT blah7",
                         "depth": 0,
                         "as_list": True,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -129,6 +138,7 @@ class MysqlPillarTestCase(TestCase):
                         "query": "SELECT blah8",
                         "depth": 0,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": [1],
                         "ignore_null": False,
                     },
@@ -139,10 +149,22 @@ class MysqlPillarTestCase(TestCase):
                         "query": "SELECT blah9",
                         "depth": 0,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": [1, 2],
                         "ignore_null": False,
                     },
                 ],
+                [
+                    None,
+                    {
+                        "query": "SELECT json1",
+                        "depth": 0,
+                        "as_list": False,
+                        "as_json": True,
+                        "with_lists": None,
+                        "ignore_null": False,
+                    },
+                ],
             ],
             qbuffer,
         )
@@ -159,6 +181,7 @@ class MysqlPillarTestCase(TestCase):
                 "5": {"query": "SELECT blah5"},
                 "6": {"query": "SELECT blah6", "depth": 2},
                 "7": {"query": "SELECT blah7", "as_list": True},
+                "8": {"query": "SELECT json1", "as_json": True},
             },
         )
         qbuffer = return_data.extract_queries(args, kwargs)
@@ -170,6 +193,7 @@ class MysqlPillarTestCase(TestCase):
                         "query": "SELECT blah",
                         "depth": 0,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -180,6 +204,7 @@ class MysqlPillarTestCase(TestCase):
                         "query": "SELECT blah2",
                         "depth": 0,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -190,6 +215,7 @@ class MysqlPillarTestCase(TestCase):
                         "query": "SELECT blah3",
                         "depth": 0,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -200,6 +226,7 @@ class MysqlPillarTestCase(TestCase):
                         "query": "SELECT blah4",
                         "depth": 2,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -210,6 +237,7 @@ class MysqlPillarTestCase(TestCase):
                         "query": "SELECT blah5",
                         "depth": 0,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -220,6 +248,7 @@ class MysqlPillarTestCase(TestCase):
                         "query": "SELECT blah6",
                         "depth": 2,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -230,6 +259,18 @@ class MysqlPillarTestCase(TestCase):
                         "query": "SELECT blah7",
                         "depth": 0,
                         "as_list": True,
+                        "as_json": False,
+                        "with_lists": None,
+                        "ignore_null": False,
+                    },
+                ],
+                [
+                    "8",
+                    {
+                        "query": "SELECT json1",
+                        "depth": 0,
+                        "as_list": False,
+                        "as_json": True,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -261,6 +302,7 @@ class MysqlPillarTestCase(TestCase):
                         "query": "SELECT blah1",
                         "depth": 0,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -271,6 +313,7 @@ class MysqlPillarTestCase(TestCase):
                         "query": "SELECT blah2",
                         "depth": 2,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -281,6 +324,7 @@ class MysqlPillarTestCase(TestCase):
                         "query": "SELECT blah3",
                         "depth": 0,
                         "as_list": True,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -291,6 +335,7 @@ class MysqlPillarTestCase(TestCase):
                         "query": "SELECT blah1",
                         "depth": 0,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -301,6 +346,7 @@ class MysqlPillarTestCase(TestCase):
                         "query": "SELECT blah2",
                         "depth": 2,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -311,6 +357,7 @@ class MysqlPillarTestCase(TestCase):
                         "query": "SELECT blah3",
                         "depth": 0,
                         "as_list": True,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -349,6 +396,7 @@ class MysqlPillarTestCase(TestCase):
                         "query": "SELECT blah",
                         "depth": 0,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -359,6 +407,7 @@ class MysqlPillarTestCase(TestCase):
                         "query": "SELECT blah2",
                         "depth": 0,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -369,6 +418,7 @@ class MysqlPillarTestCase(TestCase):
                         "query": "SELECT blah3",
                         "depth": 0,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -379,6 +429,7 @@ class MysqlPillarTestCase(TestCase):
                         "query": "SELECT blah4",
                         "depth": 2,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -389,6 +440,7 @@ class MysqlPillarTestCase(TestCase):
                         "query": "SELECT blah5",
                         "depth": 0,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -399,6 +451,7 @@ class MysqlPillarTestCase(TestCase):
                         "query": "SELECT blah6",
                         "depth": 0,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -409,6 +462,7 @@ class MysqlPillarTestCase(TestCase):
                         "query": "SELECT blah7",
                         "depth": 2,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -419,6 +473,7 @@ class MysqlPillarTestCase(TestCase):
                         "query": "SELECT blah8",
                         "depth": 0,
                         "as_list": True,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -440,6 +495,7 @@ class MysqlPillarTestCase(TestCase):
                         "query": "SELECT blah",
                         "depth": 0,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -450,6 +506,7 @@ class MysqlPillarTestCase(TestCase):
                         "query": "SELECT blah2",
                         "depth": 0,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
diff --git a/tests/unit/pillar/test_sqlcipher.py b/tests/unit/pillar/test_sqlcipher.py
index d7e9eed6f6..6f7b21fb3f 100644
--- a/tests/unit/pillar/test_sqlcipher.py
+++ b/tests/unit/pillar/test_sqlcipher.py
@@ -38,6 +38,7 @@ class SQLCipherPillarTestCase(TestCase):
                         "query": "SELECT blah",
                         "depth": 0,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -48,6 +49,7 @@ class SQLCipherPillarTestCase(TestCase):
                         "query": "SELECT blah2",
                         "depth": 0,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -58,6 +60,7 @@ class SQLCipherPillarTestCase(TestCase):
                         "query": "SELECT blah3",
                         "depth": 0,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -68,6 +71,7 @@ class SQLCipherPillarTestCase(TestCase):
                         "query": "SELECT blah4",
                         "depth": 2,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -78,6 +82,7 @@ class SQLCipherPillarTestCase(TestCase):
                         "query": "SELECT blah5",
                         "depth": 0,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -88,6 +93,7 @@ class SQLCipherPillarTestCase(TestCase):
                         "query": "SELECT blah6",
                         "depth": 2,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -98,6 +104,7 @@ class SQLCipherPillarTestCase(TestCase):
                         "query": "SELECT blah7",
                         "depth": 0,
                         "as_list": True,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -108,6 +115,7 @@ class SQLCipherPillarTestCase(TestCase):
                         "query": "SELECT blah8",
                         "depth": 0,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": [1],
                         "ignore_null": False,
                     },
@@ -118,6 +126,7 @@ class SQLCipherPillarTestCase(TestCase):
                         "query": "SELECT blah9",
                         "depth": 0,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": [1, 2],
                         "ignore_null": False,
                     },
@@ -149,6 +158,7 @@ class SQLCipherPillarTestCase(TestCase):
                         "query": "SELECT blah",
                         "depth": 0,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -159,6 +169,7 @@ class SQLCipherPillarTestCase(TestCase):
                         "query": "SELECT blah2",
                         "depth": 0,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -169,6 +180,7 @@ class SQLCipherPillarTestCase(TestCase):
                         "query": "SELECT blah3",
                         "depth": 0,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -179,6 +191,7 @@ class SQLCipherPillarTestCase(TestCase):
                         "query": "SELECT blah4",
                         "depth": 2,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -189,6 +202,7 @@ class SQLCipherPillarTestCase(TestCase):
                         "query": "SELECT blah5",
                         "depth": 0,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -199,6 +213,7 @@ class SQLCipherPillarTestCase(TestCase):
                         "query": "SELECT blah6",
                         "depth": 2,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -209,6 +224,7 @@ class SQLCipherPillarTestCase(TestCase):
                         "query": "SELECT blah7",
                         "depth": 0,
                         "as_list": True,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -240,6 +256,7 @@ class SQLCipherPillarTestCase(TestCase):
                         "query": "SELECT blah1",
                         "depth": 0,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -250,6 +267,7 @@ class SQLCipherPillarTestCase(TestCase):
                         "query": "SELECT blah2",
                         "depth": 2,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -260,6 +278,7 @@ class SQLCipherPillarTestCase(TestCase):
                         "query": "SELECT blah3",
                         "depth": 0,
                         "as_list": True,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -270,6 +289,7 @@ class SQLCipherPillarTestCase(TestCase):
                         "query": "SELECT blah1",
                         "depth": 0,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -280,6 +300,7 @@ class SQLCipherPillarTestCase(TestCase):
                         "query": "SELECT blah2",
                         "depth": 2,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -290,6 +311,7 @@ class SQLCipherPillarTestCase(TestCase):
                         "query": "SELECT blah3",
                         "depth": 0,
                         "as_list": True,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -328,6 +350,7 @@ class SQLCipherPillarTestCase(TestCase):
                         "query": "SELECT blah",
                         "depth": 0,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -338,6 +361,7 @@ class SQLCipherPillarTestCase(TestCase):
                         "query": "SELECT blah2",
                         "depth": 0,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -348,6 +372,7 @@ class SQLCipherPillarTestCase(TestCase):
                         "query": "SELECT blah3",
                         "depth": 0,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -358,6 +383,7 @@ class SQLCipherPillarTestCase(TestCase):
                         "query": "SELECT blah4",
                         "depth": 2,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -368,6 +394,7 @@ class SQLCipherPillarTestCase(TestCase):
                         "query": "SELECT blah5",
                         "depth": 0,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -378,6 +405,7 @@ class SQLCipherPillarTestCase(TestCase):
                         "query": "SELECT blah6",
                         "depth": 0,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -388,6 +416,7 @@ class SQLCipherPillarTestCase(TestCase):
                         "query": "SELECT blah7",
                         "depth": 2,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -398,6 +427,7 @@ class SQLCipherPillarTestCase(TestCase):
                         "query": "SELECT blah8",
                         "depth": 0,
                         "as_list": True,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -419,6 +449,7 @@ class SQLCipherPillarTestCase(TestCase):
                         "query": "SELECT blah",
                         "depth": 0,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -429,6 +460,7 @@ class SQLCipherPillarTestCase(TestCase):
                         "query": "SELECT blah2",
                         "depth": 0,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
diff --git a/tests/unit/pillar/test_sqlite3.py b/tests/unit/pillar/test_sqlite3.py
index da780682e7..69efd0a3e8 100644
--- a/tests/unit/pillar/test_sqlite3.py
+++ b/tests/unit/pillar/test_sqlite3.py
@@ -38,6 +38,7 @@ class SQLite3PillarTestCase(TestCase):
                         "query": "SELECT blah",
                         "depth": 0,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -48,6 +49,7 @@ class SQLite3PillarTestCase(TestCase):
                         "query": "SELECT blah2",
                         "depth": 0,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -58,6 +60,7 @@ class SQLite3PillarTestCase(TestCase):
                         "query": "SELECT blah3",
                         "depth": 0,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -68,6 +71,7 @@ class SQLite3PillarTestCase(TestCase):
                         "query": "SELECT blah4",
                         "depth": 2,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -78,6 +82,7 @@ class SQLite3PillarTestCase(TestCase):
                         "query": "SELECT blah5",
                         "depth": 0,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -88,6 +93,7 @@ class SQLite3PillarTestCase(TestCase):
                         "query": "SELECT blah6",
                         "depth": 2,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -98,6 +104,7 @@ class SQLite3PillarTestCase(TestCase):
                         "query": "SELECT blah7",
                         "depth": 0,
                         "as_list": True,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -108,6 +115,7 @@ class SQLite3PillarTestCase(TestCase):
                         "query": "SELECT blah8",
                         "depth": 0,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": [1],
                         "ignore_null": False,
                     },
@@ -118,6 +126,7 @@ class SQLite3PillarTestCase(TestCase):
                         "query": "SELECT blah9",
                         "depth": 0,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": [1, 2],
                         "ignore_null": False,
                     },
@@ -149,6 +158,7 @@ class SQLite3PillarTestCase(TestCase):
                         "query": "SELECT blah",
                         "depth": 0,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -159,6 +169,7 @@ class SQLite3PillarTestCase(TestCase):
                         "query": "SELECT blah2",
                         "depth": 0,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -169,6 +180,7 @@ class SQLite3PillarTestCase(TestCase):
                         "query": "SELECT blah3",
                         "depth": 0,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -179,6 +191,7 @@ class SQLite3PillarTestCase(TestCase):
                         "query": "SELECT blah4",
                         "depth": 2,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -189,6 +202,7 @@ class SQLite3PillarTestCase(TestCase):
                         "query": "SELECT blah5",
                         "depth": 0,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -199,6 +213,7 @@ class SQLite3PillarTestCase(TestCase):
                         "query": "SELECT blah6",
                         "depth": 2,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -209,6 +224,7 @@ class SQLite3PillarTestCase(TestCase):
                         "query": "SELECT blah7",
                         "depth": 0,
                         "as_list": True,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -240,6 +256,7 @@ class SQLite3PillarTestCase(TestCase):
                         "query": "SELECT blah1",
                         "depth": 0,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -250,6 +267,7 @@ class SQLite3PillarTestCase(TestCase):
                         "query": "SELECT blah2",
                         "depth": 2,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -260,6 +278,7 @@ class SQLite3PillarTestCase(TestCase):
                         "query": "SELECT blah3",
                         "depth": 0,
                         "as_list": True,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -270,6 +289,7 @@ class SQLite3PillarTestCase(TestCase):
                         "query": "SELECT blah1",
                         "depth": 0,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -280,6 +300,7 @@ class SQLite3PillarTestCase(TestCase):
                         "query": "SELECT blah2",
                         "depth": 2,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -290,6 +311,7 @@ class SQLite3PillarTestCase(TestCase):
                         "query": "SELECT blah3",
                         "depth": 0,
                         "as_list": True,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -328,6 +350,7 @@ class SQLite3PillarTestCase(TestCase):
                         "query": "SELECT blah",
                         "depth": 0,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -338,6 +361,7 @@ class SQLite3PillarTestCase(TestCase):
                         "query": "SELECT blah2",
                         "depth": 0,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -348,6 +372,7 @@ class SQLite3PillarTestCase(TestCase):
                         "query": "SELECT blah3",
                         "depth": 0,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -358,6 +383,7 @@ class SQLite3PillarTestCase(TestCase):
                         "query": "SELECT blah4",
                         "depth": 2,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -368,6 +394,7 @@ class SQLite3PillarTestCase(TestCase):
                         "query": "SELECT blah5",
                         "depth": 0,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -378,6 +405,7 @@ class SQLite3PillarTestCase(TestCase):
                         "query": "SELECT blah6",
                         "depth": 0,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -388,6 +416,7 @@ class SQLite3PillarTestCase(TestCase):
                         "query": "SELECT blah7",
                         "depth": 2,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -398,6 +427,7 @@ class SQLite3PillarTestCase(TestCase):
                         "query": "SELECT blah8",
                         "depth": 0,
                         "as_list": True,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -419,6 +449,7 @@ class SQLite3PillarTestCase(TestCase):
                         "query": "SELECT blah",
                         "depth": 0,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
@@ -429,6 +460,7 @@ class SQLite3PillarTestCase(TestCase):
                         "query": "SELECT blah2",
                         "depth": 0,
                         "as_list": False,
+                        "as_json": False,
                         "with_lists": None,
                         "ignore_null": False,
                     },
-- 
2.33.0


