Skip to content

Add notebook template clone and delete-clones endpoints - #709

Open
g-bar wants to merge 23 commits into
mainfrom
clone-notebook
Open

Add notebook template clone and delete-clones endpoints#709
g-bar wants to merge 23 commits into
mainfrom
clone-notebook

Conversation

@g-bar

@g-bar g-bar commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Usecase

For the education plan there exists a template project id where the faculty can upload, delete, update notebooks.
The course vlab contains also related projects for each of the students, the notebooks that the faculty uploads in the template project must be synced to the "child" projects.

Currently this happens through the UI, through multiple calls to POST /analysis-notebook-template,
POST /{entity_route}/{entity_id}/assets ,POST /contribution

This can result in a high number of api calls n_notebooks x n_target_projects x ( n_assets + n_contributions)
This moves most of that logic to the backend to cut number of api calls

To be merged only after: #703
since the name is used to match the notebook in source to corresponding notebooks in target projects.

New endpoints

POST /analysis-notebook-template/{id}/clone

Clones a private notebook into one or more target projects
Upserts by name: updates existing private notebooks to match the source (matched by name), creates new ones
Copies assets (S3) and syncs contributions to match the source

POST /analysis-notebook-template/{id}/delete-clones

Deletes notebooks matching the source name in the target projects
Assets and contributions removed via cascade

Validation

Source must be private
Source project cannot be in the target list
User must be admin of source and all target projects
Any existing notebook with the same name in a target project must be private

Tests

Auth cases: not admin of source, not admin of target, member not admin, source in target, public source, public existing in target — for both endpoints

Clone: asset copy, contribution sync (old removed, new created), upsert on second clone
Delete: clone then delete, verify 404 on deleted notebook

@codecov

codecov Bot commented Aug 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Flag Coverage Δ
pytest 97.81% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
app/queries/utils.py 100.00% <100.00%> (ø)
app/routers/analysis_notebook_template.py 100.00% <100.00%> (ø)
app/schemas/analysis_notebook_template.py 100.00% <100.00%> (ø)
app/service/analysis_notebook_template.py 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

entity_id=existing.id,
asset_id=asset.id,
)
clone_db = existing

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If the AnalysisNotebookTemplate has been already used in any AnalysisNotebookExecution, are we sure that we want to update the existing model and assets?
The ipynb in AnalysisNotebookResult wouldn't be related to the ipynb in AnalysisNotebookTemplate anymore, that can be fine but it should be stated explicitly.

Upserts by name: updates existing private notebooks, creates new ones.
Assets and contributions are synced to match the source.
"""
notebook, _ = _get_validated_clone_source_and_targets(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

There should be a lock in the db to prevent concurrent calls trying to clone the same notebook template.

Upserts by name: updates existing private notebooks, creates new ones.
Assets and contributions are synced to match the source.
"""
notebook, _ = _get_validated_clone_source_and_targets(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

For clarity, notebook can be renamed to source_notebook or source or similar names.

) -> NotebookDeleteClonesResponse:
"""Delete notebooks matching the source name in the target projects.

Only private notebooks are deleted. Contributions and assets are removed via cascade.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The deletion can fail if the AnalysisNotebookTemplate has been linked to AnalysisNotebookExecution.
In that case, a proper error should be returned.

id_: uuid.UUID,
json_model: NotebookCloneRequest,
) -> NotebookCloneResponse:
"""Clone a private notebook into one or more target projects.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This new endpoint is special because it's different from the usual CRUD endpoints in entitycore and it won't work in entitysdk without the implementation of a custom logic.
It's also the first one that involves a copy between different projects.
In general it would be better if entitysdk is kept updated to support all the endpoints of entitycore, but are there use cases for this endpoint in entitysdk?

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.

2 participants