OasisLMF / OasisPlatform

Loss modelling platform.
BSD 3-Clause "New" or "Revised" License
40 stars 17 forks source link

Passing analysis/model settings as a(n optional) parameter when creating a new analysis or model #1056

Closed amir-monshi closed 3 months ago

amir-monshi commented 4 months ago

production

Issue Description

Currently creating an analysis with custom settings is done with two calls i.e. create analysis, then update settings. But if the second call fails there is no point for to keep the newly created analysis object around. A workaround would be to delete the analysis if update settings fail but that’s not ideal and the next analysis id will increment by 1 which is not so nice specially if user has many failed attempts. Is it possible to patch V2 api to have settings passed to create call as an optional parameter (or have a new endpoint for this) and if the underlying settings call fails, then analysis is not created in oasis db at all? (edited)

Version / Environment information

versions <= 2.3.5rc1

sambles commented 4 months ago

Update the AnalysisSerializer so settings accepts and validates analysis settings JSON on POST

{
  "name": "analysis_name",
  "portfolio": {id},
  "model": {id},
  "complex_model_data_files": [ ... ], 
  "settings": {  ... entire analysis settings json ... } 
}

would needs custom to_internal_value, create, and update methods https://www.django-rest-framework.org/api-guide/serializers/#overriding-serialization-and-deserialization-behavior

sambles commented 4 months ago

Note: the same logic should also apply to model settings when creating a model