Skip to content

Commit d77c780

Browse files
authored
fix passing version has headers (#396)
1 parent 955a58d commit d77c780

3 files changed

Lines changed: 23 additions & 6 deletions

File tree

databricks_cli/jobs/cli.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def delete_cli(api_client, job_id, version):
179179
Deletes the specified job.
180180
"""
181181
check_version(api_client, version)
182-
JobsApi(api_client).delete_job(job_id, version)
182+
JobsApi(api_client).delete_job(job_id, version=version)
183183

184184

185185
@click.command(context_settings=CONTEXT_SETTINGS)
@@ -195,7 +195,7 @@ def get_cli(api_client, job_id, version):
195195
Describes the metadata for a job.
196196
"""
197197
check_version(api_client, version)
198-
click.echo(pretty_format(JobsApi(api_client).get_job(job_id, version)))
198+
click.echo(pretty_format(JobsApi(api_client).get_job(job_id, version=version)))
199199

200200

201201
@click.command(context_settings=CONTEXT_SETTINGS)
@@ -230,7 +230,7 @@ def run_now_cli(api_client, job_id, jar_params, notebook_params, python_params,
230230
python_params = json_loads(python_params) if python_params else None
231231
spark_submit_params = json_loads(spark_submit_params) if spark_submit_params else None
232232
res = JobsApi(api_client).run_now(
233-
job_id, jar_params_json, notebook_params_json, python_params, spark_submit_params, version)
233+
job_id, jar_params_json, notebook_params_json, python_params, spark_submit_params, version=version)
234234
click.echo(pretty_format(res))
235235

236236

databricks_cli/sdk/api_client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,15 @@ def perform_query(self, method, path, data = {}, headers = None, files=None, ver
124124
warnings.simplefilter("ignore", exceptions.InsecureRequestWarning)
125125
if method == 'GET':
126126
translated_data = {k: _translate_boolean_to_query_param(data[k]) for k in data}
127-
resp = self.session.request(method, self.get_url(path), params = translated_data,
127+
resp = self.session.request(method, self.get_url(path, version=version), params = translated_data,
128128
verify = self.verify, headers = headers)
129129
else:
130130
if files is None:
131-
resp = self.session.request(method, self.get_url(path), data = json.dumps(data),
131+
resp = self.session.request(method, self.get_url(path, version=version), data = json.dumps(data),
132132
verify = self.verify, headers = headers)
133133
else:
134134
# Multipart file upload
135-
resp = self.session.request(method, self.get_url(path), files = files, data = data,
135+
resp = self.session.request(method, self.get_url(path, version=version), files = files, data = data,
136136
verify = self.verify, headers = headers)
137137
try:
138138
resp.raise_for_status()

tests/jobs/test_cli.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,23 @@ def test_list_limit(jobs_api_mock):
297297
assert jobs_api_mock.list_jobs.call_args[1]['version'] == '2.1'
298298

299299

300+
@provide_conf
301+
def test_get_job_21(jobs_api_mock):
302+
with mock.patch('databricks_cli.jobs.cli.click.echo') as echo_mock:
303+
jobs_api_mock.get_job.return_value = LIST_21_RETURN['jobs'][0]
304+
runner = CliRunner()
305+
runner.invoke(cli.get_cli, ['--job-id', '1', '--version', '2.1'])
306+
assert jobs_api_mock.get_job.call_args == mock.call('1', version='2.1')
307+
assert echo_mock.call_args[0][0] == pretty_format(LIST_21_RETURN['jobs'][0])
308+
309+
310+
@provide_conf
311+
def test_delete_job_21(jobs_api_mock):
312+
runner = CliRunner()
313+
runner.invoke(cli.delete_cli, ['--job-id', '1', '--version', '2.1'])
314+
assert jobs_api_mock.delete_job.call_args == mock.call('1', version='2.1')
315+
316+
300317
@provide_conf
301318
def test_check_version():
302319
# Without calling `databricks jobs configure --version=2.1`

0 commit comments

Comments
 (0)