Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API support for bulk object deletion #3436

Closed
lamoni opened this issue Aug 19, 2019 · 5 comments
Closed

API support for bulk object deletion #3436

lamoni opened this issue Aug 19, 2019 · 5 comments
Assignees
Labels
status: accepted This issue has been accepted for implementation type: feature Introduction of new functionality to the application
Milestone

Comments

@lamoni
Copy link

lamoni commented Aug 19, 2019

Environment

  • Python version: Python 3.7
  • NetBox version: 2.6.2

Proposed Functionality

Allow bulk deletion of sites and devices (preferably anything) through API end-point.

Use Case

We have a use case that requires bulk deletion of sites and devices for automated deployment and testing of a Netbox instance. Currently, we have to iterate through the list of objects and delete them 1 by 1 (i.e. 1 HTTP request per device/site/whatever), this can take upwards of minutes. We can bulk create just fine (which reduced time to finish by a lot), but can't bulk delete. The GUI has the ability, but there isn't an API endpoint to do so.

@lamoni lamoni changed the title API support for bulk device deletion API support for bulk device/site deletion Aug 19, 2019
@lampwins
Copy link
Contributor

This has been in the back of my mind for a while, and I am surprised it has not come up before now. As we look to make UI improvements down the road, this will be needed.

We should be able to do this with a non-detail action route on our modified ModelViewSet class.

I would want to be able to pass a list of PKs or a list of objects that use the same queryset field lookup logic we implemented not long ago, as the quest body.

For example for sites, you could pass either:

[1, 4, 6]

Or

[{"name": "Site A"}, {"name": "Site B"}, {"name": "Site C"}]

@lampwins lampwins added API change status: under review Further discussion is needed to determine this issue's scope and/or implementation type: feature Introduction of new functionality to the application labels Aug 19, 2019
@jeremystretch jeremystretch changed the title API support for bulk device/site deletion API support for bulk object deletion Aug 26, 2019
@jeremystretch jeremystretch added status: accepted This issue has been accepted for implementation and removed status: under review Further discussion is needed to determine this issue's scope and/or implementation labels Dec 13, 2019
@gunnertwin
Copy link

I also have a requirement for this. I'm pulling data from Azure and want my netbox to match my Azure estate exactly. So if someone deletes a vnet in Azure, that vnet also needs to be removed in Netbox. So I would like to run my pipeline which will initially bulk delete everything and then add the current state of Azure

@jeremystretch jeremystretch added needs milestone Awaiting prioritization for inclusion with a future NetBox release and removed status: accepted This issue has been accepted for implementation needs milestone Awaiting prioritization for inclusion with a future NetBox release labels Jul 24, 2020
@jeremystretch jeremystretch added this to the v2.10 milestone Jul 24, 2020
@jeremystretch jeremystretch added the status: accepted This issue has been accepted for implementation label Jul 24, 2020
@jeremystretch jeremystretch self-assigned this Sep 15, 2020
@jeremystretch
Copy link
Member

I've made good progress on this in the branch 3436-api-bulk-update, however I've hit a wall troubleshooting an OpenAPI schema generation issue. The introduction of the bulk delete view and subsequent support for the DELETE HTTP action under a list endpoint results in a duplicate operation ID when generating the schema:

SwaggerValidationError at /api/docs/

spec validation failed: {'ssv': 'Duplicate operationId: circuits_circuit-terminations_delete'}

@jeremystretch
Copy link
Member

After a lot of digging, the sticking point seems to be the get_keys() method of DRF's CoreAPI SchemaGenerator class. Essentially, because we've introduced a custom operation (bulk_destroy), it's getting assigned a schema operation ID based on the HTTP method (DELETE), which conflicts with the DELETE operation on the detail route (i.e. DELETE /api/dcim/sites/1/).

At present, the only workaround seems to be to replicate both the drf_yasg and rest_framework schema generators, since the non-default actions are hard-coded. This probably justifies raising upstream to DRF and/or drf_yasg.

@jeremystretch
Copy link
Member

I figured out a workaround by monkey-patching DRF's is_custom_action() function. Obviously not ideal, but it's definitely the lowest-touch approach. It's probably still worth pursuing upstream, but given the current state of drf_yasg versus DRF's internal OpenAPI schema development, I'm not sure where to start.

jeremystretch added a commit that referenced this issue Sep 22, 2020
jeremystretch added a commit that referenced this issue Sep 22, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: accepted This issue has been accepted for implementation type: feature Introduction of new functionality to the application
Projects
None yet
Development

No branches or pull requests

4 participants