Skip to content

Commit

Permalink
Requery features after write_relation_values
Browse files Browse the repository at this point in the history
  • Loading branch information
manisandro committed Oct 11, 2024
1 parent ce39d5b commit c101fe1
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions src/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,12 +490,17 @@ def post(self, dataset):
get_identity(), translator, dataset, feature, files
)
if 'error' not in result:
result['feature']['relationValues'] = data_service.write_relation_values(get_identity(), result['feature']['id'], feature.get('relationValues', '{}'), request.files, translator, True)
return result['feature'], 201
else:
error_code = result.get('error_code') or 404
error_details = result.get('error_details') or {}
api.abort(error_code, result['error'], **error_details)
relationValues = data_service.write_relation_values(get_identity(), result['feature']['id'], feature.get('relationValues', '{}'), request.files, translator, True)
# Requery feature because the write_relation_values may change the feature through DB triggers
result = data_service.show(get_identity(), translator, dataset, id, feature['crs']['properties']['name'])
if 'error' not in result:
feature = result['feature']
feature['relationValues'] = relationValues
return feature, 201

error_code = result.get('error_code') or 404
error_details = result.get('error_details') or {}
api.abort(error_code, result['error'], **error_details)


@api.route('/<path:dataset>/multipart/<id>')
Expand Down Expand Up @@ -536,12 +541,17 @@ def put(self, dataset, id):
get_identity(), translator, dataset, id, feature, files
)
if 'error' not in result:
result['feature']['relationValues'] = data_service.write_relation_values(get_identity(), result['feature']['id'], feature.get('relationValues', {}), request.files, translator)
return result['feature']
else:
error_code = result.get('error_code') or 404
error_details = result.get('error_details') or {}
api.abort(error_code, result['error'], **error_details)
relationValues = data_service.write_relation_values(get_identity(), result['feature']['id'], feature.get('relationValues', {}), request.files, translator)
# Requery feature because the write_relation_values may change the feature through DB triggers
result = data_service.show(get_identity(), translator, dataset, id, feature['crs']['properties']['name'])
if 'error' not in result:
feature = result['feature']
feature['relationValues'] = relationValues
return feature

error_code = result.get('error_code') or 404
error_details = result.get('error_details') or {}
api.abort(error_code, result['error'], **error_details)


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

0 comments on commit c101fe1

Please sign in to comment.