pelias / api

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

TypeError exception if parent source is null #1515

Closed HueyNemud closed 3 years ago

HueyNemud commented 3 years ago

Hi,

Since 5f4bf2e392c99aaaa7afc41b0a116b6cc11b6eb3, documents with no parent sources raise an exception TypeError: Cannot read property 'toLowerCase' of null during a forward geocoding query. See the full stacktrace below.

This is apparently due to _.get(place, ``${placeType}_source``, ['whosonfirst']) in middleware/normalizeParentIds.js. If a place has no source, place.${placeType}_source is not undefined but contains [null] therefore the default value ['whosonfirst'] is never returned.

TypeError: Cannot read property 'toLowerCase' of undefined
    at Object.module.exports.lowercase (/home/bertrand/dev/pelias-geohistorical/pelias-api-gh/node_modules/pelias-model/util/transform.js:7:14)
    at Document.setSource (/home/bertrand/dev/pelias-geohistorical/pelias-api-gh/node_modules/pelias-model/Document.js:172:22)
    at new Document (/home/bertrand/dev/pelias-geohistorical/pelias-api-gh/node_modules/pelias-model/Document.js:49:8)
    at makeNewId (/home/bertrand/dev/pelias-geohistorical/pelias-api-gh/middleware/normalizeParentIds.js:72:13)
    at /home/bertrand/dev/pelias-geohistorical/pelias-api-gh/middleware/normalizeParentIds.js:51:39
    at Array.forEach (<anonymous>)
    at normalizeParentIds (/home/bertrand/dev/pelias-geohistorical/pelias-api-gh/middleware/normalizeParentIds.js:33:16)
    at Array.map (<anonymous>)
    at /home/bertrand/dev/pelias-geohistorical/pelias-api-gh/middleware/normalizeParentIds.js:18:25
    at Layer.handle [as handle_request] (/home/bertrand/dev/pelias-geohistorical/pelias-api-gh/node_modules/express/lib/router/layer.js:95:5)
orangejulius commented 3 years ago

Hi @HueyNemud,

I think our good friend @Joxit has already proposed a fix for this over in https://github.com/pelias/api/pull/1513. Can you test it out and confirm it fixes everything?

Thanks!

Joxit commented 3 years ago

Hi there, if you are using docker, you can pick this tag : pelias/api:joxit-fix-normalizeParentIds