Skip to content

Commit 8543b83

Browse files
committed
Requery features after write_relation_values
1 parent ce39d5b commit 8543b83

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

src/server.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -490,12 +490,17 @@ def post(self, dataset):
490490
get_identity(), translator, dataset, feature, files
491491
)
492492
if 'error' not in result:
493-
result['feature']['relationValues'] = data_service.write_relation_values(get_identity(), result['feature']['id'], feature.get('relationValues', '{}'), request.files, translator, True)
494-
return result['feature'], 201
495-
else:
496-
error_code = result.get('error_code') or 404
497-
error_details = result.get('error_details') or {}
498-
api.abort(error_code, result['error'], **error_details)
493+
relationValues = data_service.write_relation_values(get_identity(), result['feature']['id'], feature.get('relationValues', '{}'), request.files, translator, True)
494+
# Requery feature because the write_relation_values may change the feature through DB triggers
495+
result = data_service.show(get_identity(), translator, dataset, result['feature']['id'], feature['crs']['properties']['name'])
496+
if 'error' not in result:
497+
feature = result['feature']
498+
feature['relationValues'] = relationValues
499+
return feature, 201
500+
501+
error_code = result.get('error_code') or 404
502+
error_details = result.get('error_details') or {}
503+
api.abort(error_code, result['error'], **error_details)
499504

500505

501506
@api.route('/<path:dataset>/multipart/<id>')
@@ -536,12 +541,17 @@ def put(self, dataset, id):
536541
get_identity(), translator, dataset, id, feature, files
537542
)
538543
if 'error' not in result:
539-
result['feature']['relationValues'] = data_service.write_relation_values(get_identity(), result['feature']['id'], feature.get('relationValues', {}), request.files, translator)
540-
return result['feature']
541-
else:
542-
error_code = result.get('error_code') or 404
543-
error_details = result.get('error_details') or {}
544-
api.abort(error_code, result['error'], **error_details)
544+
relationValues = data_service.write_relation_values(get_identity(), result['feature']['id'], feature.get('relationValues', {}), request.files, translator)
545+
# Requery feature because the write_relation_values may change the feature through DB triggers
546+
result = data_service.show(get_identity(), translator, dataset, id, feature['crs']['properties']['name'])
547+
if 'error' not in result:
548+
feature = result['feature']
549+
feature['relationValues'] = relationValues
550+
return feature
551+
552+
error_code = result.get('error_code') or 404
553+
error_details = result.get('error_details') or {}
554+
api.abort(error_code, result['error'], **error_details)
545555

546556

547557
@api.route('/<path:dataset>/attachment')

0 commit comments

Comments
 (0)