Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions experimental/python/databricks/bundles/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,11 @@ def _load_resources(

for function in functions:
try:
resources, diagnostics = diagnostics.extend_tuple(
function_resources, diagnostics = diagnostics.extend_tuple(
_load_resources_from_function(bundle, function)
)

resources.add_resources(function_resources)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if separate functions use the same resource key?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will add a diagnostic error (that will prevent deployment) and return a bundle containing the first resource. There is a test for it.

except Exception as exc:
diagnostics = diagnostics.extend(
Diagnostics.from_exception(
Expand Down Expand Up @@ -342,7 +344,7 @@ def _explain_common_import_error(exc: Exception) -> Diagnostics:
# a common case when default name of the module is not found
# we can give a hint to the user how to fix it
explanation = """Make sure to create a new Python file at resources/__init__.py with contents:

from databricks.bundles.core import load_resources_from_current_package_module


Expand Down
49 changes: 49 additions & 0 deletions experimental/python/databricks_tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
_Args,
_Conf,
_load_object,
_load_resources,
_parse_args,
_parse_bundle_info,
_relativize_location,
Expand Down Expand Up @@ -296,3 +297,51 @@ def test_conf_from_dict():
],
venv_path="venv",
)


def test_load_resources():
bundle = Bundle(target="default")

def load_resources_1() -> Resources:
resources = Resources()
resources.add_job(
resource_name="my_job_1",
job={"name": "Job 1"},
location=Location(file="my_job_1.py", line=42, column=1),
)

return resources

def load_resources_2() -> Resources:
resources = Resources()
resources.add_job(
resource_name="my_job_2",
job={"name": "Job 2"},
location=Location(file="my_job_2.py", line=42, column=1),
)

return resources

resources, diagnostics = _load_resources(
bundle=bundle,
functions=[
load_resources_1,
load_resources_2,
],
)

assert not diagnostics.has_error()

assert resources.jobs == {
"my_job_1": Job(name="Job 1"),
"my_job_2": Job(name="Job 2"),
}

assert resources._locations == {
("resources", "jobs", "my_job_1"): Location(
file="my_job_1.py", line=42, column=1
),
("resources", "jobs", "my_job_2"): Location(
file="my_job_2.py", line=42, column=1
),
}
Loading