# Improvement PUT API

* improves error processing and response on PUT endpoint
* consolidates improved error processing into central method for all API endpoints
This commit is contained in:
2026-07-10 13:58:23 +02:00
parent b9c453fdd2
commit b4f2e3232a
2 changed files with 38 additions and 33 deletions
+10 -2
View File
@@ -6,6 +6,7 @@ Created on: 24.01.22
"""
import json
import uuid
from abc import abstractmethod
from django.contrib.gis import geos
@@ -171,13 +172,20 @@ class AbstractModelAPISerializer:
Returns:
"""
if not id:
raise ValueError("No id provided. The id is expected to live in the URL!")
# First if there is an external identifier linked to an internal one, so we can continue with the internal
try:
ext_id = ExternalIdentifier.objects.get(external_id=id)
id = ext_id.internal_id
except ObjectDoesNotExist:
# No external id found - let's hope the given id exists internally
pass
# Not found as external id - let's check whether this is a valid uuid and therefore
# potentially an internal id
try:
uuid.UUID(id)
except ValueError:
raise AssertionError(f"'{id}' is neither a known external identifier nor a valid uuid.")
obj = self.model.objects.get(
id=id,