We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[CT-371] [Bug] CLI vars in packages.yml and selectors.yml don't work.
When we did the work to separate out rendering of secrets, a bug was introduced where instead of using cli_vars to construct the contexts for packages and selectors, we use the entire yaml context (which is also a dict). Because of this we get errors like: "Object of type method is not JSON serializable" and also vars are not found when rendering.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `core/dbt/config/renderer.py`
Content:
```
1 from typing import Dict, Any, Tuple, Optional, Union, Callable
2 
3 from dbt.clients.jinja import get_rendered, catch_jinja
4 from dbt.context.target import TargetContext
5 from dbt.context.secret import SecretContext
6 from dbt.context.base import BaseContext
7 from dbt.contracts.connection import HasCredentials
8 from dbt.exceptions import DbtProjectError, CompilationException, RecursionException
9 from dbt.utils import deep_map_render
10 
11 
12 Keypath = Tuple[Union[str, int], ...]
13 
14 
15 class BaseRenderer:
16     def __init__(self, context: Dict[str, Any]) -> None:
17         self.context = context
18 
19     @property
20     def name(self):
21         return "Rendering"
22 
23     def should_render_keypath(self, keypath: Keypath) -> bool:
24         return True
25 
26     def render_entry(self, value: Any, keypath: Keypath) -> Any:
27         if not self.should_render_keypath(keypath):
28             return value
29 
30         return self.render_value(value, keypath)
31 
32     def render_value(self, value: Any, keypath: Optional[Keypath] = None) -> Any:
33         # keypath is ignored.
34         # if it wasn't read as a string, ignore it
35         if not isinstance(value, str):
36             return value
37         try:
38             with catch_jinja():
39                 return get_rendered(value, self.context, native=True)
40         except CompilationException as exc:
41             msg = f"Could not render {value}: {exc.msg}"
42             raise CompilationException(msg) from exc
43 
44     def render_data(self, data: Dict[str, Any]) -> Dict[str, Any]:
45         try:
46             return deep_map_render(self.render_entry, data)
47         except RecursionException:
48             raise DbtProjectError(
49                 f"Cycle detected: {self.name} input has a reference to itself", project=data
50             )
51 
52 
53 def _list_if_none(value):
54     if value is None:
55         value = []
56     return value
57 
58 
59 def _dict_if_none(value):
60     if value is None:
61         value = {}
62     return value
63 
64 
65 def _list_if_none_or_string(value):
66     value = _list_if_none(value)
67     if isinstance(value, str):
68         return [value]
69     return value
70 
71 
72 class ProjectPostprocessor(Dict[Keypath, Callable[[Any], Any]]):
73     def __init__(self):
74         super().__init__()
75 
76         self[("on-run-start",)] = _list_if_none_or_string
77         self[("on-run-end",)] = _list_if_none_or_string
78 
79         for k in ("models", "seeds", "snapshots"):
80             self[(k,)] = _dict_if_none
81             self[(k, "vars")] = _dict_if_none
82             self[(k, "pre-hook")] = _list_if_none_or_string
83             self[(k, "post-hook")] = _list_if_none_or_string
84         self[("seeds", "column_types")] = _dict_if_none
85 
86     def postprocess(self, value: Any, key: Keypath) -> Any:
87         if key in self:
88             handler = self[key]
89             return handler(value)
90 
91         return value
92 
93 
94 class DbtProjectYamlRenderer(BaseRenderer):
95     _KEYPATH_HANDLERS = ProjectPostprocessor()
96 
97     def __init__(
98         self, profile: Optional[HasCredentials] = None, cli_vars: Optional[Dict[str, Any]] = None
99     ) -> None:
100         # Generate contexts here because we want to save the context
101         # object in order to retrieve the env_vars. This is almost always
102         # a TargetContext, but in the debug task we want a project
103         # even when we don't have a profile.
104         if cli_vars is None:
105             cli_vars = {}
106         if profile:
107             self.ctx_obj = TargetContext(profile, cli_vars)
108         else:
109             self.ctx_obj = BaseContext(cli_vars)  # type:ignore
110         context = self.ctx_obj.to_dict()
111         super().__init__(context)
112 
113     @property
114     def name(self):
115         "Project config"
116 
117     def get_package_renderer(self) -> BaseRenderer:
118         return PackageRenderer(self.context)
119 
120     def get_selector_renderer(self) -> BaseRenderer:
121         return SelectorRenderer(self.context)
122 
123     def render_project(
124         self,
125         project: Dict[str, Any],
126         project_root: str,
127     ) -> Dict[str, Any]:
128         """Render the project and insert the project root after rendering."""
129         rendered_project = self.render_data(project)
130         rendered_project["project-root"] = project_root
131         return rendered_project
132 
133     def render_packages(self, packages: Dict[str, Any]):
134         """Render the given packages dict"""
135         package_renderer = self.get_package_renderer()
136         return package_renderer.render_data(packages)
137 
138     def render_selectors(self, selectors: Dict[str, Any]):
139         selector_renderer = self.get_selector_renderer()
140         return selector_renderer.render_data(selectors)
141 
142     def render_entry(self, value: Any, keypath: Keypath) -> Any:
143         result = super().render_entry(value, keypath)
144         return self._KEYPATH_HANDLERS.postprocess(result, keypath)
145 
146     def should_render_keypath(self, keypath: Keypath) -> bool:
147         if not keypath:
148             return True
149 
150         first = keypath[0]
151         # run hooks are not rendered
152         if first in {"on-run-start", "on-run-end", "query-comment"}:
153             return False
154 
155         # don't render vars blocks until runtime
156         if first == "vars":
157             return False
158 
159         if first in {"seeds", "models", "snapshots", "tests"}:
160             keypath_parts = {(k.lstrip("+ ") if isinstance(k, str) else k) for k in keypath}
161             # model-level hooks
162             if "pre-hook" in keypath_parts or "post-hook" in keypath_parts:
163                 return False
164 
165         return True
166 
167 
168 class SelectorRenderer(BaseRenderer):
169     @property
170     def name(self):
171         return "Selector config"
172 
173 
174 class SecretRenderer(BaseRenderer):
175     def __init__(self, cli_vars: Optional[Dict[str, Any]] = None) -> None:
176         # Generate contexts here because we want to save the context
177         # object in order to retrieve the env_vars.
178         if cli_vars is None:
179             cli_vars = {}
180         self.ctx_obj = SecretContext(cli_vars)
181         context = self.ctx_obj.to_dict()
182         super().__init__(context)
183 
184     @property
185     def name(self):
186         return "Secret"
187 
188 
189 class ProfileRenderer(SecretRenderer):
190     @property
191     def name(self):
192         return "Profile"
193 
194 
195 class PackageRenderer(SecretRenderer):
196     @property
197     def name(self):
198         return "Packages config"
199
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/core/dbt/config/renderer.py b/core/dbt/config/renderer.py
--- a/core/dbt/config/renderer.py
+++ b/core/dbt/config/renderer.py
@@ -115,10 +115,10 @@
         "Project config"
 
     def get_package_renderer(self) -> BaseRenderer:
-        return PackageRenderer(self.context)
+        return PackageRenderer(self.ctx_obj.cli_vars)
 
     def get_selector_renderer(self) -> BaseRenderer:
-        return SelectorRenderer(self.context)
+        return SelectorRenderer(self.ctx_obj.cli_vars)
 
     def render_project(
         self,

{"golden_diff": "diff --git a/core/dbt/config/renderer.py b/core/dbt/config/renderer.py\n--- a/core/dbt/config/renderer.py\n+++ b/core/dbt/config/renderer.py\n@@ -115,10 +115,10 @@\n         \"Project config\"\n \n     def get_package_renderer(self) -> BaseRenderer:\n-        return PackageRenderer(self.context)\n+        return PackageRenderer(self.ctx_obj.cli_vars)\n \n     def get_selector_renderer(self) -> BaseRenderer:\n-        return SelectorRenderer(self.context)\n+        return SelectorRenderer(self.ctx_obj.cli_vars)\n \n     def render_project(\n         self,\n", "issue": "[CT-371] [Bug] CLI vars in packages.yml and selectors.yml don't work.\nWhen we did the work to separate out rendering of secrets, a bug was introduced where instead of using cli_vars to construct the contexts for packages and selectors, we use the entire yaml context (which is also a dict). Because of this we get errors like: \"Object of type method is not JSON serializable\" and also vars are not found when rendering.\n", "before_files": [{"content": "from typing import Dict, Any, Tuple, Optional, Union, Callable\n\nfrom dbt.clients.jinja import get_rendered, catch_jinja\nfrom dbt.context.target import TargetContext\nfrom dbt.context.secret import SecretContext\nfrom dbt.context.base import BaseContext\nfrom dbt.contracts.connection import HasCredentials\nfrom dbt.exceptions import DbtProjectError, CompilationException, RecursionException\nfrom dbt.utils import deep_map_render\n\n\nKeypath = Tuple[Union[str, int], ...]\n\n\nclass BaseRenderer:\n    def __init__(self, context: Dict[str, Any]) -> None:\n        self.context = context\n\n    @property\n    def name(self):\n        return \"Rendering\"\n\n    def should_render_keypath(self, keypath: Keypath) -> bool:\n        return True\n\n    def render_entry(self, value: Any, keypath: Keypath) -> Any:\n        if not self.should_render_keypath(keypath):\n            return value\n\n        return self.render_value(value, keypath)\n\n    def render_value(self, value: Any, keypath: Optional[Keypath] = None) -> Any:\n        # keypath is ignored.\n        # if it wasn't read as a string, ignore it\n        if not isinstance(value, str):\n            return value\n        try:\n            with catch_jinja():\n                return get_rendered(value, self.context, native=True)\n        except CompilationException as exc:\n            msg = f\"Could not render {value}: {exc.msg}\"\n            raise CompilationException(msg) from exc\n\n    def render_data(self, data: Dict[str, Any]) -> Dict[str, Any]:\n        try:\n            return deep_map_render(self.render_entry, data)\n        except RecursionException:\n            raise DbtProjectError(\n                f\"Cycle detected: {self.name} input has a reference to itself\", project=data\n            )\n\n\ndef _list_if_none(value):\n    if value is None:\n        value = []\n    return value\n\n\ndef _dict_if_none(value):\n    if value is None:\n        value = {}\n    return value\n\n\ndef _list_if_none_or_string(value):\n    value = _list_if_none(value)\n    if isinstance(value, str):\n        return [value]\n    return value\n\n\nclass ProjectPostprocessor(Dict[Keypath, Callable[[Any], Any]]):\n    def __init__(self):\n        super().__init__()\n\n        self[(\"on-run-start\",)] = _list_if_none_or_string\n        self[(\"on-run-end\",)] = _list_if_none_or_string\n\n        for k in (\"models\", \"seeds\", \"snapshots\"):\n            self[(k,)] = _dict_if_none\n            self[(k, \"vars\")] = _dict_if_none\n            self[(k, \"pre-hook\")] = _list_if_none_or_string\n            self[(k, \"post-hook\")] = _list_if_none_or_string\n        self[(\"seeds\", \"column_types\")] = _dict_if_none\n\n    def postprocess(self, value: Any, key: Keypath) -> Any:\n        if key in self:\n            handler = self[key]\n            return handler(value)\n\n        return value\n\n\nclass DbtProjectYamlRenderer(BaseRenderer):\n    _KEYPATH_HANDLERS = ProjectPostprocessor()\n\n    def __init__(\n        self, profile: Optional[HasCredentials] = None, cli_vars: Optional[Dict[str, Any]] = None\n    ) -> None:\n        # Generate contexts here because we want to save the context\n        # object in order to retrieve the env_vars. This is almost always\n        # a TargetContext, but in the debug task we want a project\n        # even when we don't have a profile.\n        if cli_vars is None:\n            cli_vars = {}\n        if profile:\n            self.ctx_obj = TargetContext(profile, cli_vars)\n        else:\n            self.ctx_obj = BaseContext(cli_vars)  # type:ignore\n        context = self.ctx_obj.to_dict()\n        super().__init__(context)\n\n    @property\n    def name(self):\n        \"Project config\"\n\n    def get_package_renderer(self) -> BaseRenderer:\n        return PackageRenderer(self.context)\n\n    def get_selector_renderer(self) -> BaseRenderer:\n        return SelectorRenderer(self.context)\n\n    def render_project(\n        self,\n        project: Dict[str, Any],\n        project_root: str,\n    ) -> Dict[str, Any]:\n        \"\"\"Render the project and insert the project root after rendering.\"\"\"\n        rendered_project = self.render_data(project)\n        rendered_project[\"project-root\"] = project_root\n        return rendered_project\n\n    def render_packages(self, packages: Dict[str, Any]):\n        \"\"\"Render the given packages dict\"\"\"\n        package_renderer = self.get_package_renderer()\n        return package_renderer.render_data(packages)\n\n    def render_selectors(self, selectors: Dict[str, Any]):\n        selector_renderer = self.get_selector_renderer()\n        return selector_renderer.render_data(selectors)\n\n    def render_entry(self, value: Any, keypath: Keypath) -> Any:\n        result = super().render_entry(value, keypath)\n        return self._KEYPATH_HANDLERS.postprocess(result, keypath)\n\n    def should_render_keypath(self, keypath: Keypath) -> bool:\n        if not keypath:\n            return True\n\n        first = keypath[0]\n        # run hooks are not rendered\n        if first in {\"on-run-start\", \"on-run-end\", \"query-comment\"}:\n            return False\n\n        # don't render vars blocks until runtime\n        if first == \"vars\":\n            return False\n\n        if first in {\"seeds\", \"models\", \"snapshots\", \"tests\"}:\n            keypath_parts = {(k.lstrip(\"+ \") if isinstance(k, str) else k) for k in keypath}\n            # model-level hooks\n            if \"pre-hook\" in keypath_parts or \"post-hook\" in keypath_parts:\n                return False\n\n        return True\n\n\nclass SelectorRenderer(BaseRenderer):\n    @property\n    def name(self):\n        return \"Selector config\"\n\n\nclass SecretRenderer(BaseRenderer):\n    def __init__(self, cli_vars: Optional[Dict[str, Any]] = None) -> None:\n        # Generate contexts here because we want to save the context\n        # object in order to retrieve the env_vars.\n        if cli_vars is None:\n            cli_vars = {}\n        self.ctx_obj = SecretContext(cli_vars)\n        context = self.ctx_obj.to_dict()\n        super().__init__(context)\n\n    @property\n    def name(self):\n        return \"Secret\"\n\n\nclass ProfileRenderer(SecretRenderer):\n    @property\n    def name(self):\n        return \"Profile\"\n\n\nclass PackageRenderer(SecretRenderer):\n    @property\n    def name(self):\n        return \"Packages config\"\n", "path": "core/dbt/config/renderer.py"}], "after_files": [{"content": "from typing import Dict, Any, Tuple, Optional, Union, Callable\n\nfrom dbt.clients.jinja import get_rendered, catch_jinja\nfrom dbt.context.target import TargetContext\nfrom dbt.context.secret import SecretContext\nfrom dbt.context.base import BaseContext\nfrom dbt.contracts.connection import HasCredentials\nfrom dbt.exceptions import DbtProjectError, CompilationException, RecursionException\nfrom dbt.utils import deep_map_render\n\n\nKeypath = Tuple[Union[str, int], ...]\n\n\nclass BaseRenderer:\n    def __init__(self, context: Dict[str, Any]) -> None:\n        self.context = context\n\n    @property\n    def name(self):\n        return \"Rendering\"\n\n    def should_render_keypath(self, keypath: Keypath) -> bool:\n        return True\n\n    def render_entry(self, value: Any, keypath: Keypath) -> Any:\n        if not self.should_render_keypath(keypath):\n            return value\n\n        return self.render_value(value, keypath)\n\n    def render_value(self, value: Any, keypath: Optional[Keypath] = None) -> Any:\n        # keypath is ignored.\n        # if it wasn't read as a string, ignore it\n        if not isinstance(value, str):\n            return value\n        try:\n            with catch_jinja():\n                return get_rendered(value, self.context, native=True)\n        except CompilationException as exc:\n            msg = f\"Could not render {value}: {exc.msg}\"\n            raise CompilationException(msg) from exc\n\n    def render_data(self, data: Dict[str, Any]) -> Dict[str, Any]:\n        try:\n            return deep_map_render(self.render_entry, data)\n        except RecursionException:\n            raise DbtProjectError(\n                f\"Cycle detected: {self.name} input has a reference to itself\", project=data\n            )\n\n\ndef _list_if_none(value):\n    if value is None:\n        value = []\n    return value\n\n\ndef _dict_if_none(value):\n    if value is None:\n        value = {}\n    return value\n\n\ndef _list_if_none_or_string(value):\n    value = _list_if_none(value)\n    if isinstance(value, str):\n        return [value]\n    return value\n\n\nclass ProjectPostprocessor(Dict[Keypath, Callable[[Any], Any]]):\n    def __init__(self):\n        super().__init__()\n\n        self[(\"on-run-start\",)] = _list_if_none_or_string\n        self[(\"on-run-end\",)] = _list_if_none_or_string\n\n        for k in (\"models\", \"seeds\", \"snapshots\"):\n            self[(k,)] = _dict_if_none\n            self[(k, \"vars\")] = _dict_if_none\n            self[(k, \"pre-hook\")] = _list_if_none_or_string\n            self[(k, \"post-hook\")] = _list_if_none_or_string\n        self[(\"seeds\", \"column_types\")] = _dict_if_none\n\n    def postprocess(self, value: Any, key: Keypath) -> Any:\n        if key in self:\n            handler = self[key]\n            return handler(value)\n\n        return value\n\n\nclass DbtProjectYamlRenderer(BaseRenderer):\n    _KEYPATH_HANDLERS = ProjectPostprocessor()\n\n    def __init__(\n        self, profile: Optional[HasCredentials] = None, cli_vars: Optional[Dict[str, Any]] = None\n    ) -> None:\n        # Generate contexts here because we want to save the context\n        # object in order to retrieve the env_vars. This is almost always\n        # a TargetContext, but in the debug task we want a project\n        # even when we don't have a profile.\n        if cli_vars is None:\n            cli_vars = {}\n        if profile:\n            self.ctx_obj = TargetContext(profile, cli_vars)\n        else:\n            self.ctx_obj = BaseContext(cli_vars)  # type:ignore\n        context = self.ctx_obj.to_dict()\n        super().__init__(context)\n\n    @property\n    def name(self):\n        \"Project config\"\n\n    def get_package_renderer(self) -> BaseRenderer:\n        return PackageRenderer(self.ctx_obj.cli_vars)\n\n    def get_selector_renderer(self) -> BaseRenderer:\n        return SelectorRenderer(self.ctx_obj.cli_vars)\n\n    def render_project(\n        self,\n        project: Dict[str, Any],\n        project_root: str,\n    ) -> Dict[str, Any]:\n        \"\"\"Render the project and insert the project root after rendering.\"\"\"\n        rendered_project = self.render_data(project)\n        rendered_project[\"project-root\"] = project_root\n        return rendered_project\n\n    def render_packages(self, packages: Dict[str, Any]):\n        \"\"\"Render the given packages dict\"\"\"\n        package_renderer = self.get_package_renderer()\n        return package_renderer.render_data(packages)\n\n    def render_selectors(self, selectors: Dict[str, Any]):\n        selector_renderer = self.get_selector_renderer()\n        return selector_renderer.render_data(selectors)\n\n    def render_entry(self, value: Any, keypath: Keypath) -> Any:\n        result = super().render_entry(value, keypath)\n        return self._KEYPATH_HANDLERS.postprocess(result, keypath)\n\n    def should_render_keypath(self, keypath: Keypath) -> bool:\n        if not keypath:\n            return True\n\n        first = keypath[0]\n        # run hooks are not rendered\n        if first in {\"on-run-start\", \"on-run-end\", \"query-comment\"}:\n            return False\n\n        # don't render vars blocks until runtime\n        if first == \"vars\":\n            return False\n\n        if first in {\"seeds\", \"models\", \"snapshots\", \"tests\"}:\n            keypath_parts = {(k.lstrip(\"+ \") if isinstance(k, str) else k) for k in keypath}\n            # model-level hooks\n            if \"pre-hook\" in keypath_parts or \"post-hook\" in keypath_parts:\n                return False\n\n        return True\n\n\nclass SelectorRenderer(BaseRenderer):\n    @property\n    def name(self):\n        return \"Selector config\"\n\n\nclass SecretRenderer(BaseRenderer):\n    def __init__(self, cli_vars: Optional[Dict[str, Any]] = None) -> None:\n        # Generate contexts here because we want to save the context\n        # object in order to retrieve the env_vars.\n        if cli_vars is None:\n            cli_vars = {}\n        self.ctx_obj = SecretContext(cli_vars)\n        context = self.ctx_obj.to_dict()\n        super().__init__(context)\n\n    @property\n    def name(self):\n        return \"Secret\"\n\n\nclass ProfileRenderer(SecretRenderer):\n    @property\n    def name(self):\n        return \"Profile\"\n\n\nclass PackageRenderer(SecretRenderer):\n    @property\n    def name(self):\n        return \"Packages config\"\n", "path": "core/dbt/config/renderer.py"}]}