pelias / api

HTTP API for Pelias Geocoder
http://pelias.io
MIT License
221 stars 162 forks source link

debug: clone debug params to ensure they are not mutated before being rendered #1553

Closed missinglink closed 3 years ago

missinglink commented 3 years ago

When debugging a query today I noticed that the output of geocoding.debug[x]["controller:search"]["ES_response"].docs doesn't accurately reflect what is returned from elasticsearch.

It turns out that the objects are being mutated in subsequent steps and the output is deferred until after that, so what we're seeing is not the state of the object at ES response time so much as the state of the objects at the end of the request lifecycle.

This PR simply makes a deep copy of the objects so we render the debug as it was at that moment in time.

The code is wrapped in if( req.clean.enableElasticDebug ) so I'm not concerned about the perf impact.

missinglink commented 3 years ago

This does in fact return very different ES_response data:

.rw-r--r-- 51k peter 16 Aug 13:23 -N  test/unit/fixture/berlin_response.json
.rw-r--r-- 39k peter 16 Aug 16:06 -N  test/unit/fixture/berlin_response_new.json