AttributeError when opening RetrieveModelVersion in a web browser for a ModelVersion ID that does not exist
Sentry Issue: ARKINDEX-BACKEND-1DZ
AttributeError: 'ModelVersionsRetrieve' object has no attribute 'model_version'
(4 additional frame(s) were not displayed)
...
File "rest_framework/renderers.py", line 724, in render
context = self.get_context(data, accepted_media_type, renderer_context)
File "rest_framework/renderers.py", line 656, in get_context
raw_data_put_form = self.get_raw_data_form(data, view, 'PUT', request)
File "rest_framework/renderers.py", line 552, in get_raw_data_form
serializer = view.get_serializer(instance=instance)
File "rest_framework/generics.py", line 109, in get_serializer
kwargs.setdefault('context', self.get_serializer_context())
File "arkindex/training/api.py", line 132, in get_serializer_context
Using cli.request('RetrieveModelVersion', id='aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa')
will return HTTP 404. Using the frontend on /model-version/aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa/
shows a Not found.
error correctly. But opening /api/v1/modelversion/aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa
with your web browser causes an AttributeError!
This is probably caused by this line. self.model_version
is set by get_object
, but when the ModelVersion does not exist, it results in a NotFound
exception and the attribute is not set. When the HTML rendering tries to retrieve the serializer to still display an UPDATE
HTML form, this line gets called but self.model_version
is not set.
Also note that self.model_version
should be a cached_property
, following a common pattern seen in other endpoints such as here.