Skip to content

nautobot.apps.dcim

Public DCIM extension points for Nautobot apps.

nautobot.apps.dcim.SkipAutoComponentCreation

Context manager that suppresses Device/Module create_components() on save.

Inside the with block, Device.save() and Module.save() skip their call to self.create_components() for newly created instances. Default behaviour (instantiate components from the related DeviceType / ModuleType templates) is restored automatically on exit, including when the block raises.

The context manager is re-entrant: an outer with block continues to suppress after an inner block exits. It is exception-safe: state is restored even if the wrapped code raises.

Implementation uses contextvars.ContextVar, so the flag is correctly scoped per asyncio task / Celery worker invocation and does not leak across threads.

Example
from nautobot.apps.dcim import SkipAutoComponentCreation
from nautobot.dcim.models import Device

with SkipAutoComponentCreation():
    device = Device.objects.create(...)  # no auto-components

__enter__()

Activate suppression for the calling context.

__exit__(exc_type, exc, tb)

Restore the previous suppression state.

__init__()

Initialize without entering the context yet.

nautobot.apps.dcim.is_auto_component_creation_suppressed()

Return True if a SkipAutoComponentCreation context is active.

Intended primarily for introspection and tests. Production code should normally use the SkipAutoComponentCreation context manager directly.