Dagdaf commited on
Commit
d2d7f20
·
1 Parent(s): 87ab64c

Refactor attribute response handling to utilize centralized key removal mapping

Browse files

- Introduced a `KEYS_TO_REMOVE_MAPPING` dictionary in `tool_utils.py` to streamline the removal of unnecessary keys based on attribute types.
- Updated `process_attribute_response` to leverage this mapping, enhancing maintainability and reducing redundancy across multiple attribute handling files.
- Simplified the attribute response processing in `tools_account_attribute.py`, `tools_boolean_attribute.py`, `tools_datetime_attribute.py`, `tools_decimal_attribute.py`, `tools_document_attribute.py`, `tools_drawing_attribute.py`, `tools_duration_attribute.py`, `tools_enum_attribute.py`, `tools_image_attribute.py`, `tools_record_attribute.py`, `tools_role_attribute.py`, and `tools_text_attribute.py` by replacing manual key removal logic with a call to the updated function.

tools/attributes_tools/tools_account_attribute.py CHANGED
@@ -137,39 +137,10 @@ def get_account_attribute(
137
 
138
  result = requests_._get_request(f"{ATTRIBUTE_ENDPOINT}/{application_system_name}/{attribute_global_alias}")
139
 
140
- # Check if the request was successful and has the expected structure
141
- if not result.get('success', False):
142
- return result
143
-
144
- result_body = result.get('raw_response')
145
- if result_body is None:
146
- result.update({"error": "No response data received from server"})
147
- return result
148
-
149
- # Check if result_body has the expected 'response' key
150
- if not isinstance(result_body, dict) or 'response' not in result_body:
151
- result.update({"error": "Unexpected response structure from server"})
152
- return result
153
-
154
- keys_to_remove = ['isUnique', 'isIndexed', 'isMandatory', 'isOwnership', 'imageColorType', 'imagePreserveAspectRatio']
155
-
156
- for key in keys_to_remove:
157
- if key in result_body['response']:
158
- result_body['response'].pop(key, None)
159
-
160
- # Extract the data
161
- data = result_body['response']
162
-
163
- # Create the final result with the data
164
- final_result = {
165
- "success": True,
166
- "status_code": result.get("status_code", 200),
167
- "data": data,
168
- "error": None
169
- }
170
-
171
- validated = AttributeResult(**final_result)
172
- return validated.model_dump()
173
 
174
  if __name__ == "__main__":
175
  results = edit_or_create_account_attribute.invoke({
 
137
 
138
  result = requests_._get_request(f"{ATTRIBUTE_ENDPOINT}/{application_system_name}/{attribute_global_alias}")
139
 
140
+ return process_attribute_response(
141
+ request_result=result,
142
+ result_model=AttributeResult
143
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
144
 
145
  if __name__ == "__main__":
146
  results = edit_or_create_account_attribute.invoke({
tools/attributes_tools/tools_boolean_attribute.py CHANGED
@@ -103,39 +103,10 @@ def get_boolean_attribute(
103
 
104
  result = requests_._get_request(f"{ATTRIBUTE_ENDPOINT}/{application_system_name}/{attribute_global_alias}")
105
 
106
- # Check if the request was successful and has the expected structure
107
- if not result.get('success', False):
108
- return result
109
-
110
- result_body = result.get('raw_response')
111
- if result_body is None:
112
- result.update({"error": "No response data received from server"})
113
- return result
114
-
115
- # Check if result_body has the expected 'response' key
116
- if not isinstance(result_body, dict) or 'response' not in result_body:
117
- result.update({"error": "Unexpected response structure from server"})
118
- return result
119
-
120
- keys_to_remove = ['isMultiValue', 'isMandatory', 'isOwnership', 'instanceGlobalAlias', 'imageColorType', 'imagePreserveAspectRatio']
121
-
122
- for key in keys_to_remove:
123
- if key in result_body['response']:
124
- result_body['response'].pop(key, None)
125
-
126
- # Extract the data
127
- data = result_body['response']
128
-
129
- # Create the final result with the data
130
- final_result = {
131
- "success": True,
132
- "status_code": result.get("status_code", 200),
133
- "data": data,
134
- "error": None
135
- }
136
-
137
- validated = AttributeResult(**final_result)
138
- return validated.model_dump()
139
 
140
  if __name__ == "__main__":
141
  results = edit_or_create_boolean_attribute.invoke({
 
103
 
104
  result = requests_._get_request(f"{ATTRIBUTE_ENDPOINT}/{application_system_name}/{attribute_global_alias}")
105
 
106
+ return process_attribute_response(
107
+ request_result=result,
108
+ result_model=AttributeResult
109
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110
 
111
  if __name__ == "__main__":
112
  results = edit_or_create_boolean_attribute.invoke({
tools/attributes_tools/tools_datetime_attribute.py CHANGED
@@ -159,39 +159,10 @@ def get_date_time_attribute(
159
 
160
  result = requests_._get_request(f"{ATTRIBUTE_ENDPOINT}/{application_system_name}/{attribute_global_alias}")
161
 
162
- # Check if the request was successful and has the expected structure
163
- if not result.get('success', False):
164
- return result
165
-
166
- result_body = result.get('raw_response')
167
- if result_body is None:
168
- result.update({"error": "No response data received from server"})
169
- return result
170
-
171
- # Check if result_body has the expected 'response' key
172
- if not isinstance(result_body, dict) or 'response' not in result_body:
173
- result.update({"error": "Unexpected response structure from server"})
174
- return result
175
-
176
- keys_to_remove = ['isUnique', 'isIndexed', 'isMultiValue', 'isMandatory', 'isOwnership', 'instanceGlobalAlias', 'imageColorType', 'imagePreserveAspectRatio']
177
-
178
- for key in keys_to_remove:
179
- if key in result_body['response']:
180
- result_body['response'].pop(key, None)
181
-
182
- # Extract the data
183
- data = result_body['response']
184
-
185
- # Create the final result with the data
186
- final_result = {
187
- "success": True,
188
- "status_code": result.get("status_code", 200),
189
- "data": data,
190
- "error": None
191
- }
192
-
193
- validated = AttributeResult(**final_result)
194
- return validated.model_dump()
195
 
196
  if __name__ == "__main__":
197
  results = edit_or_create_date_time_attribute.invoke({
 
159
 
160
  result = requests_._get_request(f"{ATTRIBUTE_ENDPOINT}/{application_system_name}/{attribute_global_alias}")
161
 
162
+ return process_attribute_response(
163
+ request_result=result,
164
+ result_model=AttributeResult
165
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
166
 
167
  if __name__ == "__main__":
168
  results = edit_or_create_date_time_attribute.invoke({
tools/attributes_tools/tools_decimal_attribute.py CHANGED
@@ -129,39 +129,10 @@ def get_numeric_attribute(
129
 
130
  result = requests_._get_request(f"{ATTRIBUTE_ENDPOINT}/{application_system_name}/{attribute_global_alias}")
131
 
132
- # Check if the request was successful and has the expected structure
133
- if not result.get('success', False):
134
- return result
135
-
136
- result_body = result.get('raw_response')
137
- if result_body is None:
138
- result.update({"error": "No response data received from server"})
139
- return result
140
-
141
- # Check if result_body has the expected 'response' key
142
- if not isinstance(result_body, dict) or 'response' not in result_body:
143
- result.update({"error": "Unexpected response structure from server"})
144
- return result
145
-
146
- keys_to_remove = ['isMultiValue', 'isMandatory', 'isOwnership', 'instanceGlobalAlias', 'imageColorType', 'imagePreserveAspectRatio']
147
-
148
- for key in keys_to_remove:
149
- if key in result_body['response']:
150
- result_body['response'].pop(key, None)
151
-
152
- # Extract the data
153
- data = result_body['response']
154
-
155
- # Create the final result with the data
156
- final_result = {
157
- "success": True,
158
- "status_code": result.get("status_code", 200),
159
- "data": data,
160
- "error": None
161
- }
162
-
163
- validated = AttributeResult(**final_result)
164
- return validated.model_dump()
165
 
166
  if __name__ == "__main__":
167
  results = edit_or_create_numeric_attribute.invoke({
 
129
 
130
  result = requests_._get_request(f"{ATTRIBUTE_ENDPOINT}/{application_system_name}/{attribute_global_alias}")
131
 
132
+ return process_attribute_response(
133
+ request_result=result,
134
+ result_model=AttributeResult
135
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
136
 
137
  if __name__ == "__main__":
138
  results = edit_or_create_numeric_attribute.invoke({
tools/attributes_tools/tools_document_attribute.py CHANGED
@@ -85,7 +85,7 @@ def edit_or_create_document_attribute(
85
  "type": "Undefined",
86
  "alias": system_name
87
  },
88
- "type": "String",
89
  "format": display_format,
90
  "name": name,
91
  "description": description,
@@ -156,39 +156,10 @@ def get_document_attribute(
156
 
157
  result = requests_._get_request(f"{ATTRIBUTE_ENDPOINT}/{application_system_name}/{attribute_global_alias}")
158
 
159
- # Check if the request was successful and has the expected structure
160
- if not result.get('success', False):
161
- return result
162
-
163
- result_body = result.get('raw_response')
164
- if result_body is None:
165
- result.update({"error": "No response data received from server"})
166
- return result
167
-
168
- # Check if result_body has the expected 'response' key
169
- if not isinstance(result_body, dict) or 'response' not in result_body:
170
- result.update({"error": "Unexpected response structure from server"})
171
- return result
172
-
173
- keys_to_remove = ['isTitle', 'isUnique', 'isCalculated', 'isMandatory', 'isOwnership', 'instanceGlobalAlias', 'imageColorType', 'imagePreserveAspectRatio']
174
-
175
- for key in keys_to_remove:
176
- if key in result_body['response']:
177
- result_body['response'].pop(key, None)
178
-
179
- # Extract the data
180
- data = result_body['response']
181
-
182
- # Create the final result with the data
183
- final_result = {
184
- "success": True,
185
- "status_code": result.get("status_code", 200),
186
- "data": data,
187
- "error": None
188
- }
189
-
190
- validated = AttributeResult(**final_result)
191
- return validated.model_dump()
192
 
193
  if __name__ == "__main__":
194
  results = edit_or_create_document_attribute.invoke({
 
85
  "type": "Undefined",
86
  "alias": system_name
87
  },
88
+ "type": "Document",
89
  "format": display_format,
90
  "name": name,
91
  "description": description,
 
156
 
157
  result = requests_._get_request(f"{ATTRIBUTE_ENDPOINT}/{application_system_name}/{attribute_global_alias}")
158
 
159
+ return process_attribute_response(
160
+ request_result=result,
161
+ result_model=AttributeResult
162
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
163
 
164
  if __name__ == "__main__":
165
  results = edit_or_create_document_attribute.invoke({
tools/attributes_tools/tools_drawing_attribute.py CHANGED
@@ -32,7 +32,7 @@ def edit_or_create_drawing_attribute(
32
  "type": "Undefined",
33
  "alias": system_name
34
  },
35
- "type": "Image",
36
  "name": name,
37
  "description": description,
38
  "isTracked": write_changes_to_the_log
@@ -99,39 +99,10 @@ def get_drawing_attribute(
99
 
100
  result = requests_._get_request(f"{ATTRIBUTE_ENDPOINT}/{application_system_name}/{attribute_global_alias}")
101
 
102
- # Check if the request was successful and has the expected structure
103
- if not result.get('success', False):
104
- return result
105
-
106
- result_body = result.get('raw_response')
107
- if result_body is None:
108
- result.update({"error": "No response data received from server"})
109
- return result
110
-
111
- # Check if result_body has the expected 'response' key
112
- if not isinstance(result_body, dict) or 'response' not in result_body:
113
- result.update({"error": "Unexpected response structure from server"})
114
- return result
115
-
116
- keys_to_remove = ['isIndexed', 'isMultiValue', 'imageColorType', 'imagePreserveAspectRatio', 'isUnique', 'format', 'isCalculated', 'isTitle', 'isMandatory', 'isOwnership', 'instanceGlobalAlias']
117
-
118
- for key in keys_to_remove:
119
- if key in result_body['response']:
120
- result_body['response'].pop(key, None)
121
-
122
- # Extract the data
123
- data = result_body['response']
124
-
125
- # Create the final result with the data
126
- final_result = {
127
- "success": True,
128
- "status_code": result.get("status_code", 200),
129
- "data": data,
130
- "error": None
131
- }
132
-
133
- validated = AttributeResult(**final_result)
134
- return validated.model_dump()
135
 
136
  if __name__ == "__main__":
137
  results = edit_or_create_drawing_attribute.invoke({
 
32
  "type": "Undefined",
33
  "alias": system_name
34
  },
35
+ "type": "Drawing",
36
  "name": name,
37
  "description": description,
38
  "isTracked": write_changes_to_the_log
 
99
 
100
  result = requests_._get_request(f"{ATTRIBUTE_ENDPOINT}/{application_system_name}/{attribute_global_alias}")
101
 
102
+ return process_attribute_response(
103
+ request_result=result,
104
+ result_model=AttributeResult
105
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
106
 
107
  if __name__ == "__main__":
108
  results = edit_or_create_drawing_attribute.invoke({
tools/attributes_tools/tools_duration_attribute.py CHANGED
@@ -147,39 +147,10 @@ def get_duration_attribute(
147
 
148
  result = requests_._get_request(f"{ATTRIBUTE_ENDPOINT}/{application_system_name}/{attribute_global_alias}")
149
 
150
- # Check if the request was successful and has the expected structure
151
- if not result.get('success', False):
152
- return result
153
-
154
- result_body = result.get('raw_response')
155
- if result_body is None:
156
- result.update({"error": "No response data received from server"})
157
- return result
158
-
159
- # Check if result_body has the expected 'response' key
160
- if not isinstance(result_body, dict) or 'response' not in result_body:
161
- result.update({"error": "Unexpected response structure from server"})
162
- return result
163
-
164
- keys_to_remove = ['isUnique', 'isIndexed', 'isMultiValue', 'isMandatory', 'isOwnership', 'instanceGlobalAlias', 'imageColorType', 'imagePreserveAspectRatio']
165
-
166
- for key in keys_to_remove:
167
- if key in result_body['response']:
168
- result_body['response'].pop(key, None)
169
-
170
- # Extract the data
171
- data = result_body['response']
172
-
173
- # Create the final result with the data
174
- final_result = {
175
- "success": True,
176
- "status_code": result.get("status_code", 200),
177
- "data": data,
178
- "error": None
179
- }
180
-
181
- validated = AttributeResult(**final_result)
182
- return validated.model_dump()
183
 
184
  if __name__ == "__main__":
185
  results = edit_or_create_duration_attribute.invoke({
 
147
 
148
  result = requests_._get_request(f"{ATTRIBUTE_ENDPOINT}/{application_system_name}/{attribute_global_alias}")
149
 
150
+ return process_attribute_response(
151
+ request_result=result,
152
+ result_model=AttributeResult
153
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154
 
155
  if __name__ == "__main__":
156
  results = edit_or_create_duration_attribute.invoke({
tools/attributes_tools/tools_enum_attribute.py CHANGED
@@ -206,11 +206,8 @@ def get_enum_attribute(
206
 
207
  result = requests_._get_request(f"{ATTRIBUTE_ENDPOINT}/{application_system_name}/{attribute_global_alias}")
208
 
209
- keys_to_remove = ['isMultiValue', 'isMandatory', 'isOwnership', 'instanceGlobalAlias', 'imageColorType', 'imagePreserveAspectRatio']
210
-
211
  return process_attribute_response(
212
  request_result=result,
213
- keys_to_remove=keys_to_remove,
214
  result_model=AttributeResult
215
  )
216
 
 
206
 
207
  result = requests_._get_request(f"{ATTRIBUTE_ENDPOINT}/{application_system_name}/{attribute_global_alias}")
208
 
 
 
209
  return process_attribute_response(
210
  request_result=result,
 
211
  result_model=AttributeResult
212
  )
213
 
tools/attributes_tools/tools_image_attribute.py CHANGED
@@ -172,39 +172,10 @@ def get_image_attribute(
172
 
173
  result = requests_._get_request(f"{ATTRIBUTE_ENDPOINT}/{application_system_name}/{attribute_global_alias}")
174
 
175
- # Check if the request was successful and has the expected structure
176
- if not result.get('success', False):
177
- return result
178
-
179
- result_body = result.get('raw_response')
180
- if result_body is None:
181
- result.update({"error": "No response data received from server"})
182
- return result
183
-
184
- # Check if result_body has the expected 'response' key
185
- if not isinstance(result_body, dict) or 'response' not in result_body:
186
- result.update({"error": "Unexpected response structure from server"})
187
- return result
188
-
189
- keys_to_remove = ['isUnique', 'format', 'isCalculated', 'isTitle', 'isMandatory', 'isOwnership', 'instanceGlobalAlias']
190
-
191
- for key in keys_to_remove:
192
- if key in result_body['response']:
193
- result_body['response'].pop(key, None)
194
-
195
- # Extract the data
196
- data = result_body['response']
197
-
198
- # Create the final result with the data
199
- final_result = {
200
- "success": True,
201
- "status_code": result.get("status_code", 200),
202
- "data": data,
203
- "error": None
204
- }
205
-
206
- validated = AttributeResult(**final_result)
207
- return validated.model_dump()
208
 
209
  if __name__ == "__main__":
210
  results = edit_or_create_image_attribute.invoke({
 
172
 
173
  result = requests_._get_request(f"{ATTRIBUTE_ENDPOINT}/{application_system_name}/{attribute_global_alias}")
174
 
175
+ return process_attribute_response(
176
+ request_result=result,
177
+ result_model=AttributeResult
178
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
179
 
180
  if __name__ == "__main__":
181
  results = edit_or_create_image_attribute.invoke({
tools/attributes_tools/tools_record_attribute.py CHANGED
@@ -138,39 +138,10 @@ def get_record_attribute(
138
 
139
  result = requests_._get_request(f"{ATTRIBUTE_ENDPOINT}/{application_system_name}/{attribute_global_alias}")
140
 
141
- # Check if the request was successful and has the expected structure
142
- if not result.get('success', False):
143
- return result
144
-
145
- result_body = result.get('raw_response')
146
- if result_body is None:
147
- result.update({"error": "No response data received from server"})
148
- return result
149
-
150
- # Check if result_body has the expected 'response' key
151
- if not isinstance(result_body, dict) or 'response' not in result_body:
152
- result.update({"error": "Unexpected response structure from server"})
153
- return result
154
-
155
- keys_to_remove = ['isTitle', 'isUnique', 'isIndexed', 'isMandatory', 'isOwnership', 'imageColorType', 'imagePreserveAspectRatio']
156
-
157
- for key in keys_to_remove:
158
- if key in result_body['response']:
159
- result_body['response'].pop(key, None)
160
-
161
- # Extract the data
162
- data = result_body['response']
163
-
164
- # Create the final result with the data
165
- final_result = {
166
- "success": True,
167
- "status_code": result.get("status_code", 200),
168
- "data": data,
169
- "error": None
170
- }
171
-
172
- validated = AttributeResult(**final_result)
173
- return validated.model_dump()
174
 
175
  if __name__ == "__main__":
176
  results = edit_or_create_record_attribute.invoke({
 
138
 
139
  result = requests_._get_request(f"{ATTRIBUTE_ENDPOINT}/{application_system_name}/{attribute_global_alias}")
140
 
141
+ return process_attribute_response(
142
+ request_result=result,
143
+ result_model=AttributeResult
144
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
145
 
146
  if __name__ == "__main__":
147
  results = edit_or_create_record_attribute.invoke({
tools/attributes_tools/tools_role_attribute.py CHANGED
@@ -39,7 +39,7 @@ def edit_or_create_role_attribute(
39
  "type": "Undefined",
40
  "alias": system_name
41
  },
42
- "type": "Instance",
43
  "name": name,
44
  "description": description,
45
  "isTracked": write_changes_to_the_log,
@@ -113,39 +113,10 @@ def get_role_attribute(
113
 
114
  result = requests_._get_request(f"{ATTRIBUTE_ENDPOINT}/{application_system_name}/{attribute_global_alias}")
115
 
116
- # Check if the request was successful and has the expected structure
117
- if not result.get('success', False):
118
- return result
119
-
120
- result_body = result.get('raw_response')
121
- if result_body is None:
122
- result.update({"error": "No response data received from server"})
123
- return result
124
-
125
- # Check if result_body has the expected 'response' key
126
- if not isinstance(result_body, dict) or 'response' not in result_body:
127
- result.update({"error": "Unexpected response structure from server"})
128
- return result
129
-
130
- keys_to_remove = ['instanceGlobalAlias', 'isTitle', 'isUnique', 'isIndexed', 'isMandatory', 'isOwnership', 'imageColorType', 'imagePreserveAspectRatio']
131
-
132
- for key in keys_to_remove:
133
- if key in result_body['response']:
134
- result_body['response'].pop(key, None)
135
-
136
- # Extract the data
137
- data = result_body['response']
138
-
139
- # Create the final result with the data
140
- final_result = {
141
- "success": True,
142
- "status_code": result.get("status_code", 200),
143
- "data": data,
144
- "error": None
145
- }
146
-
147
- validated = AttributeResult(**final_result)
148
- return validated.model_dump()
149
 
150
  if __name__ == "__main__":
151
  results = edit_or_create_role_attribute.invoke({
 
39
  "type": "Undefined",
40
  "alias": system_name
41
  },
42
+ "type": "Role",
43
  "name": name,
44
  "description": description,
45
  "isTracked": write_changes_to_the_log,
 
113
 
114
  result = requests_._get_request(f"{ATTRIBUTE_ENDPOINT}/{application_system_name}/{attribute_global_alias}")
115
 
116
+ return process_attribute_response(
117
+ request_result=result,
118
+ result_model=AttributeResult
119
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120
 
121
  if __name__ == "__main__":
122
  results = edit_or_create_role_attribute.invoke({
tools/attributes_tools/tools_text_attribute.py CHANGED
@@ -212,11 +212,8 @@ def get_text_attribute(
212
 
213
  result = requests_._get_request(f"{ATTRIBUTE_ENDPOINT}/{application_system_name}/{attribute_global_alias}")
214
 
215
- keys_to_remove = ['isMultiValue', 'isMandatory', 'isOwnership', 'instanceGlobalAlias', 'imageColorType', 'imagePreserveAspectRatio']
216
-
217
  return process_attribute_response(
218
  request_result=result,
219
- keys_to_remove=keys_to_remove,
220
  result_model=AttributeResult
221
  )
222
 
 
212
 
213
  result = requests_._get_request(f"{ATTRIBUTE_ENDPOINT}/{application_system_name}/{attribute_global_alias}")
214
 
 
 
215
  return process_attribute_response(
216
  request_result=result,
 
217
  result_model=AttributeResult
218
  )
219
 
tools/tool_utils.py CHANGED
@@ -11,6 +11,20 @@ from .models import (
11
 
12
  # Common constants
13
  ATTRIBUTE_ENDPOINT = "webapi/Attribute"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
 
15
  def remove_nones(obj: Any) -> Any:
16
  """
@@ -33,7 +47,6 @@ def remove_nones(obj: Any) -> Any:
33
 
34
  def process_attribute_response(
35
  request_result: Dict[str, Any],
36
- keys_to_remove: List[str],
37
  result_model: Type[BaseModel]
38
  ) -> Dict[str, Any]:
39
  """
@@ -78,8 +91,12 @@ def process_attribute_response(
78
  # Копируем данные, чтобы не мутировать оригинал
79
  attribute_data = raw_response['response'].copy() if isinstance(raw_response['response'], dict) else raw_response['response']
80
 
81
- # Удаляем ненужные ключи (если это словарь)
82
  if isinstance(attribute_data, dict):
 
 
 
 
83
  for key in keys_to_remove:
84
  attribute_data.pop(key, None)
85
 
@@ -93,7 +110,7 @@ def process_attribute_response(
93
  if "alias" in global_alias:
94
  attribute_data["alias"] = global_alias["alias"]
95
  # type игнорируется и не добавляется
96
-
97
 
98
  # Формируем финальный результат
99
  final_result = {
 
11
 
12
  # Common constants
13
  ATTRIBUTE_ENDPOINT = "webapi/Attribute"
14
+ KEYS_TO_REMOVE_MAPPING = {
15
+ "String": ['isMultiValue', 'isMandatory', 'isOwnership', 'instanceGlobalAlias', 'imageColorType', 'imagePreserveAspectRatio'],
16
+ "Role": ['instanceGlobalAlias', 'isTitle', 'isUnique', 'isIndexed', 'isMandatory', 'isOwnership', 'imageColorType', 'imagePreserveAspectRatio'],
17
+ "Instance": ['isTitle', 'isUnique', 'isIndexed', 'isMandatory', 'isOwnership', 'imageColorType', 'imagePreserveAspectRatio'],
18
+ "Image": ['isUnique', 'format', 'isCalculated', 'isTitle', 'isMandatory', 'isOwnership', 'instanceGlobalAlias'],
19
+ "Enum": ['isMultiValue', 'isMandatory', 'isOwnership', 'instanceGlobalAlias', 'imageColorType', 'imagePreserveAspectRatio'],
20
+ "Duration": ['isUnique', 'isIndexed', 'isMultiValue', 'isMandatory', 'isOwnership', 'instanceGlobalAlias', 'imageColorType', 'imagePreserveAspectRatio'],
21
+ "Drawing": ['isIndexed', 'isMultiValue', 'imageColorType', 'imagePreserveAspectRatio', 'isUnique', 'format', 'isCalculated', 'isTitle', 'isMandatory', 'isOwnership', 'instanceGlobalAlias'],
22
+ "Document": ['isTitle', 'isUnique', 'isCalculated', 'isMandatory', 'isOwnership', 'instanceGlobalAlias', 'imageColorType', 'imagePreserveAspectRatio'],
23
+ "Decimal": ['isMultiValue', 'isMandatory', 'isOwnership', 'instanceGlobalAlias', 'imageColorType', 'imagePreserveAspectRatio'],
24
+ "DateTime": ['isUnique', 'isIndexed', 'isMultiValue', 'isMandatory', 'isOwnership', 'instanceGlobalAlias', 'imageColorType', 'imagePreserveAspectRatio'],
25
+ "Boolean": ['isMultiValue', 'isMandatory', 'isOwnership', 'instanceGlobalAlias', 'imageColorType', 'imagePreserveAspectRatio'],
26
+ "Account": ['isUnique', 'isIndexed', 'isMandatory', 'isOwnership', 'imageColorType', 'imagePreserveAspectRatio']
27
+ }
28
 
29
  def remove_nones(obj: Any) -> Any:
30
  """
 
47
 
48
  def process_attribute_response(
49
  request_result: Dict[str, Any],
 
50
  result_model: Type[BaseModel]
51
  ) -> Dict[str, Any]:
52
  """
 
91
  # Копируем данные, чтобы не мутировать оригинал
92
  attribute_data = raw_response['response'].copy() if isinstance(raw_response['response'], dict) else raw_response['response']
93
 
94
+ # Работаем только если attribute_data - словарь
95
  if isinstance(attribute_data, dict):
96
+ # Определяем тип атрибута
97
+ attr_type = attribute_data.get("type")
98
+ keys_to_remove = KEYS_TO_REMOVE_MAPPING.get(attr_type, []) # по умолчанию - пустой список
99
+ # Удаляем ненужные ключи (если это словарь)
100
  for key in keys_to_remove:
101
  attribute_data.pop(key, None)
102
 
 
110
  if "alias" in global_alias:
111
  attribute_data["alias"] = global_alias["alias"]
112
  # type игнорируется и не добавляется
113
+
114
 
115
  # Формируем финальный результат
116
  final_result = {