Skip to content

Commit deec72e

Browse files
🚑️ fix an issue with execute in DBR 13.X+ (#800)
* initial thougths about the bug * provide bugfix * add release notes
1 parent 2b21c11 commit deec72e

3 files changed

Lines changed: 34 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ This may lead to instability when using dbx API methods directly.
1212

1313
## [UNRELEASED] - YYYY-MM-DD
1414

15+
## [0.8.17] - 2023-06-18
16+
17+
### Fixed
18+
19+
- Issue with the project code update in `dbx execute` for DBR 13.X+
20+
1521
## [0.8.16] - 2023-06-10
1622

1723
### Fixed

dbx/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.8.16"
1+
__version__ = "0.8.17"

dbx/api/execute.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,31 @@ def run(self):
7474
if self._run:
7575
mlflow.end_run()
7676

77+
def _identify_runtime_version(self) -> Optional[int]:
78+
command = """
79+
import os
80+
print(os.environ.get("DATABRICKS_RUNTIME_VERSION"))
81+
"""
82+
_version_string = self._client.client.execute_command(command, verbose=False)
83+
_clean_string = None if _version_string == "None" else _version_string
84+
if not _clean_string:
85+
return None
86+
else:
87+
try:
88+
_version = int(_clean_string.split(".")[0])
89+
return _version
90+
except ValueError:
91+
dbx_echo("🚨 Cannot identify the DBR version, package may not be updated")
92+
return None
93+
94+
def _refresh_python_if_necessary(self):
95+
_version = self._identify_runtime_version()
96+
if _version and _version >= 13:
97+
dbx_echo("🔄 Restarting Python to reflect the changes in environment")
98+
refresh_command = "dbutils.library.restartPython()"
99+
self._client.client.execute_command(refresh_command, verbose=False)
100+
dbx_echo("✅ Restarting Python to reflect the changes in environment - done")
101+
77102
def install_requirements_file(self):
78103
if not self._requirements_file.exists():
79104
raise Exception(f"Requirements file provided, but doesn't exist at path {self._requirements_file}")
@@ -84,6 +109,7 @@ def install_requirements_file(self):
84109
)
85110
installation_command = f"%pip install -U -r {localized_requirements_path}"
86111
self._client.client.execute_command(installation_command, verbose=False)
112+
self._refresh_python_if_necessary()
87113
dbx_echo("Provided requirements installed")
88114

89115
def install_package(self, pip_install_extras: Optional[str]):
@@ -97,6 +123,7 @@ def install_package(self, pip_install_extras: Optional[str]):
97123
with Console().status("Installing package on the cluster 📦", spinner="dots"):
98124
self._client.install_package(localized_package_path, pip_install_extras)
99125

126+
self._refresh_python_if_necessary()
100127
dbx_echo(":white_check_mark: Installing package - done")
101128

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

0 commit comments

Comments
 (0)