Fixes #21202: Fix scoped form cloning clearing the Scope field when Scope Type changes #491

Closed
opened 2026-04-05 16:36:28 +02:00 by MrUnknownDE · 0 comments
Owner

Originally created by @pheus on 1/22/2026

Fixes: #21202

This PR adjusts ScopedForm._set_scoped_values() so it no longer clears initial['scope'] during clone form initialization.

Previously, when cloning an object with scoped fields (e.g., a Prefix scoped to Site: DC1), the form would treat the scope_type mismatch like an edit and wipe the pre-filled scope on the initial GET, forcing the user to re-select it manually.

With this change, the scope is only cleared when editing an existing object (instance.pk is set) and the scope_type has actually changed.

Thanks for taking a look! This also helps unblock the follow-up fix in #21262.

*Originally created by @pheus on 1/22/2026* ### Fixes: #21202 This PR adjusts `ScopedForm._set_scoped_values()` so it no longer clears `initial['scope']` during clone form initialization. Previously, when cloning an object with scoped fields (e.g., a Prefix scoped to `Site: DC1`), the form would treat the `scope_type` mismatch like an edit and wipe the pre-filled scope on the initial GET, forcing the user to re-select it manually. With this change, the scope is only cleared when **editing an existing object** (`instance.pk` is set) *and* the `scope_type` has actually changed. Thanks for taking a look! This also helps unblock the follow-up fix in #21262.
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/netbox#491