|
11 | 11 |
|
12 | 12 | class DefenseMutableModel(MutableBaseModel):
|
13 | 13 | _change_object_http_method = "PATCH"
|
| 14 | + _change_object_key_name = None |
| 15 | + |
| 16 | + def __init__(self, cb, model_unique_id=None, initial_data=None, force_init=False, full_doc=False): |
| 17 | + super(DefenseMutableModel, self).__init__(cb, model_unique_id=model_unique_id, initial_data=initial_data, |
| 18 | + force_init=force_init, full_doc=full_doc) |
| 19 | + if not self._change_object_key_name: |
| 20 | + self._change_object_key_name = self.primary_key |
14 | 21 |
|
15 | 22 | def _parse(self, obj):
|
16 | 23 | if type(obj) == dict and self.info_key in obj:
|
@@ -79,6 +86,12 @@ def _refresh_if_needed(self, request_ret):
|
79 | 86 | self._info = message.get(self.info_key)
|
80 | 87 | self._full_init = True
|
81 | 88 | refresh_required = False
|
| 89 | + else: |
| 90 | + if self._change_object_key_name in message.keys(): |
| 91 | + # if all we got back was an ID, try refreshing to get the entire record. |
| 92 | + log.debug("Only received an ID back from the server, forcing a refresh") |
| 93 | + self._info[self.primary_key] = message[self._change_object_key_name] |
| 94 | + refresh_required = True |
82 | 95 | else:
|
83 | 96 | # "success" is False
|
84 | 97 | raise ServerError(request_ret.status_code, message.get("message", ""),
|
@@ -131,5 +144,6 @@ class Policy(DefenseMutableModel, CreatableModelMixin):
|
131 | 144 | info_key = "policyInfo"
|
132 | 145 | swagger_meta_file = "defense/models/policyInfo.yaml"
|
133 | 146 | _change_object_http_method = "PUT"
|
| 147 | + _change_object_key_name = "policyId" |
134 | 148 |
|
135 | 149 |
|
0 commit comments