Skip to content

feat: Add Notebook-scoped packages for command submits or notebook job run#1321

Merged
sd-db merged 7 commits intodatabricks:mainfrom
fedemgp:add_notebook_scoped_packages
Apr 14, 2026
Merged

feat: Add Notebook-scoped packages for command submits or notebook job run#1321
sd-db merged 7 commits intodatabricks:mainfrom
fedemgp:add_notebook_scoped_packages

Conversation

@fedemgp
Copy link
Copy Markdown
Contributor

@fedemgp fedemgp commented Feb 5, 2026

Resolves #1320

Description

Add feature to install packages in Notebook-scoped environment for PythonCommandSubmitt and PythonNotebookUploader classes

Execution Test

I made the changes and tested it in our environment, looking that the compiled code now have the prepended package installation

All purpose cluster
image
Serverless cluster
image

Job cluster

image

Checklist

  • I have run this code in development and it appears to resolve the stated issue
  • This PR includes tests, or tests are not required/relevant for this PR
  • I have updated the CHANGELOG.md and added information about my change to the "dbt-databricks next" section.

Copy link
Copy Markdown
Collaborator

@tejassp-db tejassp-db left a comment

Choose a reason for hiding this comment

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

Have you taken this into account - The Databricks docs state "Starting with Databricks Runtime 13.0 %pip commands do not automatically restart the Python process. If you install a new package or update an existing package, you may need to use dbutils.library.restartPython() to see the new packages."

Also have you considered the recommendation on driver node sizes for notebook scoped libraries

Copy link
Copy Markdown
Collaborator

@sd-db sd-db left a comment

Choose a reason for hiding this comment

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

Thx for the PR. Took a look at the code changes(didn't review tests yet) and added comments.

Comment thread dbt/adapters/databricks/python_models/python_submissions.py Outdated
Comment thread dbt/adapters/databricks/python_models/python_submissions.py Outdated
Comment thread dbt/adapters/databricks/python_models/python_submissions.py
Comment thread dbt/adapters/databricks/python_models/python_submissions.py Outdated
Comment thread dbt/adapters/databricks/python_models/python_submissions.py Outdated
@fedemgp
Copy link
Copy Markdown
Contributor Author

fedemgp commented Feb 10, 2026

Have you taken this into account - The Databricks docs state "Starting with Databricks Runtime 13.0 %pip commands do not automatically restart the Python process. If you install a new package or update an existing package, you may need to use dbutils.library.restartPython() to see the new packages."

Also have you considered the recommendation on driver node sizes for notebook scoped libraries

I didn't take into account the recommendation to restart python process, thanks for that. I will refactor this draft PR to make it more production ready (avoiding duplicated code) and consider that.

About the how large should the driver node be, this solution is agnostic about cluster size. It will depend on the team that previously defined the cluster (no matter if it was an all purpose cluster, job cluster, whatever).

@fedemgp fedemgp force-pushed the add_notebook_scoped_packages branch 2 times, most recently from 19d86fc to 6fa5301 Compare February 11, 2026 22:31
@fedemgp fedemgp marked this pull request as ready for review February 12, 2026 12:52
@fedemgp fedemgp requested review from sd-db and tejassp-db February 18, 2026 18:24
@fedemgp fedemgp changed the title Add Notebook-scoped packages for command submits or notebook job run feat: Add Notebook-scoped packages for command submits or notebook job run Feb 25, 2026
…b run

Signed-off-by: Federico Manuel Gomez Peter <federico.gomez@payclip.com>
@fedemgp fedemgp force-pushed the add_notebook_scoped_packages branch from b0b0c48 to dcc572a Compare February 25, 2026 17:35
Copy link
Copy Markdown
Collaborator

@sd-db sd-db left a comment

Choose a reason for hiding this comment

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

I would recommend functional tests as well. I checked locally that this looks good. Would be good to add to the PR. Otherwise looks good outside of minor comments. Thx again for the PR !!

Comment thread dbt/adapters/databricks/python_models/python_submissions.py Outdated
Comment thread dbt/adapters/databricks/python_models/python_submissions.py Outdated
@tejassp-db
Copy link
Copy Markdown
Collaborator

@fedemgp can you please address the review comments.

@tejassp-db
Copy link
Copy Markdown
Collaborator

@fedemgp can you please add the functional tests?

tejassp-db and others added 3 commits March 24, 2026 16:23
Signed-off-by: Federico Manuel Gomez Peter <federico.gomez@payclip.com>
Signed-off-by: Federico Manuel Gomez Peter <federico.gomez@payclip.com>
@fedemgp
Copy link
Copy Markdown
Contributor Author

fedemgp commented Mar 25, 2026

Hello @tejassp-db, apologies for the delayed response — I was out of the office. I've now pushed the requested changes.

@fedemgp
Copy link
Copy Markdown
Contributor Author

fedemgp commented Apr 6, 2026

Hello @tejassp-db, were you able to take a look at the latest changes?

@sd-db sd-db requested a review from jprakash-db as a code owner April 14, 2026 06:18
@github-actions
Copy link
Copy Markdown

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  dbt/adapters/databricks/python_models
  python_config.py
  python_submissions.py 31
Project Total  

This report was generated by python-coverage-comment-action

@sd-db
Copy link
Copy Markdown
Collaborator

sd-db commented Apr 14, 2026

Hi @fedemgp sorry for the late reply, I was on extended leave. Thanks for the functional test + fixes. I see the tests are failing though. The fix for this should be quite simple

  • Both model fixtures in fixtures.py are missing return df — without it dbt can't materialize the result and the tests fail. Add return df at the end of both notebook_scoped_packages_cmd_api_model and notebook_scoped_packages_notebook_run_model
  • TestNotebookScopedPackagesCommandAPI references the wrong fixture — it uses notebook_scoped_packages_notebook_run_model (which has create_notebook=True) instead of notebook_scoped_packages_cmd_api_model (which has create_notebook=False). This means both test classes exercise the same notebook-upload path and the Command API path has no coverage.

You can refer to the fixes here (verified running against a live cluster).

@sd-db
Copy link
Copy Markdown
Collaborator

sd-db commented Apr 14, 2026

I see the tests are failing though

The failing github action run should have more details on the failure reason

@fedemgp
Copy link
Copy Markdown
Contributor Author

fedemgp commented Apr 14, 2026

I see the tests are failing though

The failing github action run should have more details on the failure reason

You are totally right. I thought I had run the tests locally, but I guess I was wrong. I got confused because the PR skipped the step. I've fixed them now and ran them locally. My tests passed, but some unrelated ones failed. I think they might be failing due to a lack of configuration in my dev environment.

I pushed a new commit applying the fixes you recommended. Thanks!

Copy link
Copy Markdown
Collaborator

@sd-db sd-db left a comment

Choose a reason for hiding this comment

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

Changes look good, thanks for the PR.

@sd-db sd-db merged commit e2a85e6 into databricks:main Apr 14, 2026
10 checks passed
@fedemgp
Copy link
Copy Markdown
Contributor Author

fedemgp commented Apr 15, 2026

Changes look good, thanks for the PR.

Glad to hear it, do you have an ETA of when the change will be released?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Notebook-scoped libraries feature not enable in dbt-databricks

3 participants