Skip to content

Commit

Permalink
πŸš‘οΈ fix an issue with execute in DBR 13.X+ (#800)
Browse files Browse the repository at this point in the history
* initial thougths about the bug

* provide bugfix

* add release notes
  • Loading branch information
renardeinside authored Jun 18, 2023
1 parent 2b21c11 commit deec72e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ This may lead to instability when using dbx API methods directly.

## [UNRELEASED] - YYYY-MM-DD

## [0.8.17] - 2023-06-18

### Fixed

- Issue with the project code update in `dbx execute` for DBR 13.X+

## [0.8.16] - 2023-06-10

### Fixed
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.16"
__version__ = "0.8.17"
27 changes: 27 additions & 0 deletions dbx/api/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,31 @@ def run(self):
if self._run:
mlflow.end_run()

def _identify_runtime_version(self) -> Optional[int]:
command = """
import os
print(os.environ.get("DATABRICKS_RUNTIME_VERSION"))
"""
_version_string = self._client.client.execute_command(command, verbose=False)
_clean_string = None if _version_string == "None" else _version_string
if not _clean_string:
return None
else:
try:
_version = int(_clean_string.split(".")[0])
return _version
except ValueError:
dbx_echo("🚨 Cannot identify the DBR version, package may not be updated")
return None

def _refresh_python_if_necessary(self):
_version = self._identify_runtime_version()
if _version and _version >= 13:
dbx_echo("πŸ”„ Restarting Python to reflect the changes in environment")
refresh_command = "dbutils.library.restartPython()"
self._client.client.execute_command(refresh_command, verbose=False)
dbx_echo("βœ… Restarting Python to reflect the changes in environment - done")

def install_requirements_file(self):
if not self._requirements_file.exists():
raise Exception(f"Requirements file provided, but doesn't exist at path {self._requirements_file}")
Expand All @@ -84,6 +109,7 @@ def install_requirements_file(self):
)
installation_command = f"%pip install -U -r {localized_requirements_path}"
self._client.client.execute_command(installation_command, verbose=False)
self._refresh_python_if_necessary()
dbx_echo("Provided requirements installed")

def install_package(self, pip_install_extras: Optional[str]):
Expand All @@ -97,6 +123,7 @@ def install_package(self, pip_install_extras: Optional[str]):
with Console().status("Installing package on the cluster πŸ“¦", spinner="dots"):
self._client.install_package(localized_package_path, pip_install_extras)

self._refresh_python_if_necessary()
dbx_echo(":white_check_mark: Installing package - done")

def preprocess_task_parameters(self, parameters: Union[List[str], Dict[str, str]]):
Expand Down

0 comments on commit deec72e

Please sign in to comment.