Add portable schema GUI, apply extensions, and deletion hardening#599
Add portable schema GUI, apply extensions, and deletion hardening#599christianbur wants to merge 10 commits into
Conversation
Apply only the portable-schema delta: import/export UI, choice_sets/objects apply, security_objects.json demo, PROTECT COT deletion, list columns, and reindex job batching — without replacing feature-branch branching/GraphQL code.
Align branching/portable-schema documentation with branch-aware schema apply, document COT list columns in the REST API guide, and restore the missing branch_bypass_warning.html referenced by the schema import UI. Co-authored-by: Cursor <cursoragent@cursor.com>
Fix portable-schema and REST docs; add COT deletion blockers and bulk-delete realignment with recursion guards (_netbox_private, get_registered_model, get_models). Extend deletion tests and query-count expectations. Co-authored-by: Cursor <cursoragent@cursor.com>
Collect every in-process through class via _iter_m2m_through_copies and realign inbound/outbound FKs on each copy. Use get_registered_model() for single and bulk deletes so stale class identity cannot break the collector.
Bulk-delete of rulebooks with polymorphic multiobject fields failed when stale through copies kept a previous TableNModel class on the source FK. Extend realign_inbound/outbound to patch all polymorphic through copies.
Unregister generated models and drop physical tables before ObjectType deletion so Django's ContentType collector does not SET NULL against orphaned polymorphic GFK columns. Skip field DDL when the backing table is already gone. Co-authored-by: Cursor <cursoragent@cursor.com>
Document list-column hints, bulk-delete parity, orphaned-table cleanup, and the distinction between schema-level blockers and object-field on_delete_behavior (object fields only).
Align the Top-Level Structure table with the recommended authoring order: schema_version, choice_sets, types, objects.
|
Christian seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
|
We require an approved issue before accepting PRs of this scope, and there isn't one linked here (or that I could find). This isn't a reflection on the quality of the work (the PR clearly represents significant effort), but taking on a large feature contribution without prior discussion means accepting maintenance responsibility for something we haven't had a chance to evaluate against our roadmap and architecture direction. Please open an issue describing the feature and your proposed approach. Once we've had a chance to review and approve it, a PR will be welcome. |
Summary
Adds the portable schema GUI and apply workflow on top of the existing
feature-branch backend: JSON import on the Custom Object Type add page, export tab and list export,choice_sets/objectsapply support, and a reference demo document (security_objects.json).Also includes operational hardening found while testing complex cross-COT schemas: COT deletion guards, bulk-delete reliability after dynamic model regeneration, and recursion guards for circular / polymorphic M2M graphs.
Portable schema import/export makes it straightforward for the community to share, reuse, and adopt Custom Object Type definitions as portable JSON documents.
Portable schema (GUI + apply)
choice_setsandobjectsseed data (executor + validation)portable-schema.md,rest-api.md, branch-aware apply (DDL in branch schema; COT/field metadata in main)netbox_custom_objects/schema/examples/security_objects.jsonRecommended top-level key order when authoring documents by hand:
schema_version→choice_sets→types→objectsCustom Object Type list & deletion
bulk_load_list_stats)get_deletion_blockers()— block COT delete while instances exist or other COTs reference this type in schema (AbortRequestin UI/API)Bulk delete & dynamic model stability
Fixes
ValueError: Must be "TableNModel" instanceand related collector failures aftercache_timestamp/ model regeneration:sourceFK realignment (e.g.security-rb-demo1)CustomObject.delete()uses the canonical registered model class_netbox_privateonCustomObjectto avoid broken NetBox reverse-M2M changelog traversalget_registered_model(),_model_generation_guardinget_models())Other
schedule_reindex_custom_object_type()— batch reindex enqueue on schema applysecurity_objectsapply smoke tests)Test plan
security_objects.jsonvia JSON tab (preview → apply)security-service,security-service-group, andsecurity-rb-demo1instances after schema re-apply / cache invalidationpython manage.py test netbox_custom_objects.tests.test_schema_ui netbox_custom_objects.tests.schema netbox_custom_objects.tests.test_cot_list_stats netbox_custom_objects.tests.test_deletionNotes for reviewers
security_objects.json(integration demo). Can trim or move to external reference if preferred.Co-authored-by: Cursorfrom local authoring; happy to squash on merge.feature(notmain).