Repository: dbt-labs/dbt-core

Issue:
[BUG] Command line variable ignored when supplied to command in server
### Describe the bug
When I run this command against the `cli` method in the server:
```
dbt run --vars '{period_start_date: '2019-04-01', period: 'day'}' -m buildings
```
the command line variables are ignored. Instead I would expect the command line variables to be present in the context. 

Note: partial parsing is enabled in this environment

### Steps To Reproduce
tbd


**The output of `dbt --version`:**
```
O.15.2
```

[BUG] Command line variable ignored when supplied to command in server
### Describe the bug
When I run this command against the `cli` method in the server:
```
dbt run --vars '{period_start_date: '2019-04-01', period: 'day'}' -m buildings
```
the command line variables are ignored. Instead I would expect the command line variables to be present in the context. 

Note: partial parsing is enabled in this environment

### Steps To Reproduce
tbd


**The output of `dbt --version`:**
```
O.15.2
```



Discussion:
Hi, this also happens when we run a job and pass to it variables options as part of the dbt run command.
Hi, this also happens when we run a job and pass to it variables options as part of the dbt run command.

Resolving patch:
diff --git a/core/dbt/task/rpc/cli.py b/core/dbt/task/rpc/cli.py
--- a/core/dbt/task/rpc/cli.py
+++ b/core/dbt/task/rpc/cli.py
@@ -1,5 +1,6 @@
 import abc
 import shlex
+import yaml
 from typing import Type, Optional
 
 
@@ -12,6 +13,7 @@
     Result,
 )
 from dbt.exceptions import InternalException
+from dbt.utils import parse_cli_vars
 
 from .base import RPCTask
 
@@ -36,6 +38,15 @@ def __init__(self, args, config, manifest):
 
     def set_config(self, config):
         super().set_config(config)
+
+        # read any cli vars we got and use it to update cli_vars
+        self.config.cli_vars.update(
+            parse_cli_vars(getattr(self.args, 'vars', '{}'))
+        )
+        # rewrite args.vars to reflect our merged vars
+        self.args.vars = yaml.safe_dump(self.config.cli_vars)
+        self.config.args = self.args
+
         if self.task_type is None:
             raise InternalException('task type not set for set_config')
         if issubclass(self.task_type, RemoteManifestMethod):


Test patch:
diff --git a/test/rpc/test_base.py b/test/rpc/test_base.py
--- a/test/rpc/test_base.py
+++ b/test/rpc/test_base.py
@@ -863,3 +863,25 @@ def test_missing_tag_sighup(
         querier.sighup()
 
         assert querier.wait_for_status('ready') is True
+
+
+def test_rpc_vars(
+    project_root, profiles_root, postgres_profile, unique_schema
+):
+    project = ProjectDefinition(
+        models={
+            'my_model.sql': 'select {{ var("param") }} as id',
+        },
+    )
+    querier_ctx = get_querier(
+        project_def=project,
+        project_dir=project_root,
+        profiles_dir=profiles_root,
+        schema=unique_schema,
+        test_kwargs={},
+    )
+
+    with querier_ctx as querier:
+        results = querier.async_wait_for_result(querier.cli_args('run --vars "{param: 100}"'))
+        assert len(results['results']) == 1
+        assert results['results'][0]['node']['compiled_sql'] == 'select 100 as id'