Skip to content

Commit

Permalink
🚑️ Fix parsing logic for named parameters in Jobs API 2.1 Asset-based…
Browse files Browse the repository at this point in the history
… launch (#771)

* fix docs

* finalize bugfix and add tests

* fix linting
  • Loading branch information
renardeinside authored May 10, 2023
1 parent b0dfd87 commit 1771390
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 10 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

[Please read through the Keep a Changelog (~5min)](https://keepachangelog.com/en/1.0.0/).

## [0.8.13] - 2023-05-10

### Fixed

- Issue with passing `named_parameters` for an asset-based run in Jobs API 2.1 via CLI in `dbx launch`
- Arguments used in docs for asset-based launch

## [0.8.12] - 2023-05-06

## Fixed
### Fixed

- Explicitly pin the `requests` version to avoid issues with downstream libraries

Expand Down
2 changes: 1 addition & 1 deletion dbx/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.8.12"
__version__ = "0.8.13"
3 changes: 2 additions & 1 deletion dbx/models/workflow/v2dot1/_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
StringArray,
BaseParametersMixin,
PipelineTaskParametersPayload,
NamedParametersMixin,
)


class FlexibleParametersMixin(ParametersMixin):
parameters: Optional[Union[ParamPair, StringArray]]


class PayloadElement(FlexibleParametersMixin, BaseParametersMixin, PipelineTaskParametersPayload):
class PayloadElement(FlexibleParametersMixin, BaseParametersMixin, PipelineTaskParametersPayload, NamedParametersMixin):
task_key: str
14 changes: 7 additions & 7 deletions docs/guides/general/passing_parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ All parameters should be provided in a form of a JSON-compatible payload (see ex

Examples for Jobs API 2.0:
```bash
dbx launch <workflow_name> --assets-only --parameters='{"base_parameters": {"key1": "value1", "key2": "value2"}}' # for notebook_task
dbx launch <workflow_name> --assets-only --parameters='{"parameters": ["argument1", "argument2"]}' # for spark_jar_task, spark_python_task and spark_submit_task
dbx launch <workflow_name> --from-assets --parameters='{"base_parameters": {"key1": "value1", "key2": "value2"}}' # for notebook_task
dbx launch <workflow_name> --from-assets --parameters='{"parameters": ["argument1", "argument2"]}' # for spark_jar_task, spark_python_task and spark_submit_task
```

For Jobs API 2.1, the payload format should be compliant with the [JobsRunSubmit](https://docs.databricks.com/dev-tools/api/latest/jobs.html#operation/JobsRunsSubmit).
Expand All @@ -81,27 +81,27 @@ All parameters should be provided in a form of a JSON-compatible payload (see ex

```bash
# notebook_task
dbx launch <workflow_name> --assets-only <workflow_name> --parameters='[
dbx launch <workflow_name> --from-assets <workflow_name> --parameters='[
{"task_key": "some", "base_parameters": {"a": 1, "b": 2}}
]'

# spark_python_task, python_wheel_task, spark_jar_task, spark_submit_task, python_wheel_task
dbx launch <workflow_name> --assets-only <workflow_name> --parameters='[
dbx launch <workflow_name> --from-assets <workflow_name> --parameters='[
{"task_key": "some", "parameters": ["a", "b"]}
]'

# python_wheel_task
dbx launch <workflow_name> --assets-only <workflow_name> --parameters='[
dbx launch <workflow_name> --from-assets <workflow_name> --parameters='[
{"task_key": "some", "named_parameters": {"a": 1, "b": 2}}
]'

# pipeline_task
dbx launch <workflow_name> --assets-only <workflow_name> --parameters='[
dbx launch <workflow_name> --from-assets <workflow_name> --parameters='[
{"task_key": "some", "full_refresh": true}
]'

# sql_task
dbx launch <workflow_name> --assets-only <workflow_name> --parameters='[
dbx launch <workflow_name> --from-assets <workflow_name> --parameters='[
{"task_key": "some", "parameters": {"key1": "value2"}}
]'
```
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/models/test_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,11 @@ def test_assert_based_v2dot0_not_unique():
def test_assert_based_v2dot1_good(param_raw_payload):
parsed = V2dot1AssetBasedRunPayload.from_string(param_raw_payload)
assert parsed.elements is not None


def test_asset_based_v2dot1_sample():
payload = """[
{"task_key": "main", "named_parameters": {"a": 1, "b": 2}}
]"""
parsed = V2dot1AssetBasedRunPayload.from_string(payload)
assert parsed.elements[0].named_parameters == {"a": 1, "b": 2}

0 comments on commit 1771390

Please sign in to comment.