Add notebook template clone and delete-clones endpoints - #709
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests.
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
| entity_id=existing.id, | ||
| asset_id=asset.id, | ||
| ) | ||
| clone_db = existing |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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?
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 /contributionThis 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