Skip to content

[feature] Emit a signal when an object changes organization #559

Description

@nemesifier

⚠️ not suited to first time contributors (PRs will be closed without explanation!).

Is your feature request related to a problem? Please describe.
Organization-owned models currently have no shared, public lifecycle hook for reacting to an organization change. Integrations must implement their own save-time checks and cannot consistently receive both the previous and new organization in the same transaction.

Describe the solution you'd like
Add an organization_changed signal to openwisp_users.signals, emitted by OrgMixin and inherited by ShareableOrgMixin.

The signal should emit only for existing objects whose persisted organization_id actually changed. It should use the concrete model as sender and provide instance, old_organization_id, and organization_id. It must respect update_fields, including relation names and attnames, and support deferred fields and swappable models.

The signal must run synchronously inside the transaction that saves the organization change, so receivers can make related changes atomically.

Describe alternatives you've considered
Application-specific pre-save and post-save receivers duplicate organization-change detection and cannot provide a consistent public integration point. Deferring the signal to transaction.on_commit() is unsuitable for receivers which must reconcile related tenant-owned data atomically.

Additional context
openwisp-controller needs this signal to reconcile templates and provisioned credentials when a device moves organization. A controller follow-up will depend on this issue.

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status
    To do
    Status
    To do (general)

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions