From dbf1e461dd0b4c64f5281272d2823f2f95b5d5c3 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Mon, 12 Dec 2022 10:10:05 +0100 Subject: [PATCH] base_adresse: set result id to lookup id (#72263) base_adresse data source ids are not canonical, many can match the same adress. But clients of the API does not handle this well, so it's better to always return the same id event if we know it has changed. --- passerelle/apps/base_adresse/models.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/passerelle/apps/base_adresse/models.py b/passerelle/apps/base_adresse/models.py index 9a3d5308..1ef13005 100644 --- a/passerelle/apps/base_adresse/models.py +++ b/passerelle/apps/base_adresse/models.py @@ -198,6 +198,13 @@ class BaseAdresse(AddressResource): results = self.addresses(request, q=q, lat=lat, lon=lon, citycode=citycode)['data'] for result in results: # match by id if possible if result['ban_id'] == ban_id: + # Keep the original id if the client revalidate the + # response before accepting it (like w.c.s. does). + # id can change if street name changes (case change for + # example). + # See https://dev.entrouvert.org/issues/72263 + result = result.copy() + result['id'] = id return {'data': [result]} self.logger.error('get_by_id: id %s was not found', id) return {'err': _('Address ID not found')} -- 2.37.2