Compare commits

..

1 Commits

Author SHA1 Message Date
Martin Hauser
6ca82a0901 fix(dcim): Avoid clearing scope on clone
ScopedForm._set_scoped_values() cleared initial['scope'] whenever the
scope_type differed from the instance value. During cloning (unsaved
instance), this runs on the initial GET and wipes the pre-filled scope,
forcing the user to re-select it.

Only clear the scope when editing an existing object (instance.pk set)
and the scope type has actually changed.

Fixes #21202
2026-01-22 22:34:47 +01:00
3 changed files with 3 additions and 17 deletions

View File

@@ -75,7 +75,7 @@ class ScopedForm(forms.Form):
except ObjectDoesNotExist:
pass
if self.instance and scope_type_id != self.instance.scope_type_id:
if self.instance and self.instance.pk and scope_type_id != self.instance.scope_type_id:
self.initial['scope'] = None
else:

View File

@@ -86,7 +86,7 @@ def enqueue_event(queue, instance, request, event_type):
def process_event_rules(event_rules, object_type, event_type, data, username=None, snapshots=None, request=None):
user = None # To be resolved from the username if needed
user = User.objects.get(username=username) if username else None
for event_rule in event_rules:
@@ -134,10 +134,6 @@ def process_event_rules(event_rules, object_type, event_type, data, username=Non
# Resolve the script from action parameters
script = event_rule.action_object.python_class()
# Retrieve the User if not already resolved
if user is None:
user = User.objects.get(username=username)
# Enqueue a Job to record the script's execution
from extras.jobs import ScriptJob
params = {

View File

@@ -1,6 +1,5 @@
import re
from collections import namedtuple
import logging
from django.conf import settings
from django.contrib import messages
@@ -29,8 +28,6 @@ __all__ = (
'SearchView',
)
logger = logging.getLogger(f'netbox.{__name__}')
Link = namedtuple('Link', ('label', 'viewname', 'permission', 'count'))
@@ -53,14 +50,7 @@ class HomeView(ConditionalLoginRequiredMixin, View):
# Check whether a new release is available. (Only for superusers.)
new_release = None
if request.user.is_superuser:
# cache.get() can raise if the cached value can't be unpickled after dependency upgrades
try:
latest_release = cache.get('latest_release')
except Exception:
logger.debug("Failed to read 'latest_release' from cache; deleting key", exc_info=True)
cache.delete('latest_release')
latest_release = None
latest_release = cache.get('latest_release')
if latest_release:
release_version, release_url = latest_release
if release_version > version.parse(settings.RELEASE.version):