Logging message when creating via API #8312
GillesTondini
started this conversation in
General
Replies: 1 comment
-
It looks to me like the messages could be made more consistent - see below. However the "Creating" message is logged before object creation for the API, and the "Created" message after creation for the web interface. That's why the primary key isn't shown. netbox/views/generic.py
netbox/api/views.py def perform_create(self, serializer):
model = self.queryset.model
logger = logging.getLogger('netbox.api.views.ModelViewSet')
logger.info(f"Creating new {model._meta.verbose_name}")
# Enforce object-level permissions on save()
try:
with transaction.atomic():
instance = serializer.save()
self._validate_objects(instance)
except ObjectDoesNotExist:
raise PermissionDenied()
...
def perform_update(self, serializer):
model = self.queryset.model
logger = logging.getLogger('netbox.api.views.ModelViewSet')
logger.info(f"Updating {model._meta.verbose_name} {serializer.instance} (PK: {serializer.instance.pk})") |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
When using the logger netbox.views.ObjectEditView , we have the name of the created object in the message
e.g "Created prefix 192.168.0.0/29 (PK: 15654)"
but when using the API, the message is a more generic "Creating new prefix"
We do have however the name of the object when updating, both via the API and the GUI:
"Modified prefix 192.168.0.0/29 (PK: 13804)" (GUI)
"Updating prefix 192.168.0.0/29 (PK: 15653)" (API)
Any reason it's not the same for every action?
Thanks,
Beta Was this translation helpful? Give feedback.
All reactions