mysociety / mapit

A web service to map postcodes to administrative boundaries and more
Other
268 stars 88 forks source link

Redirect error from front page postcode form #285

Closed handelaar closed 7 years ago

handelaar commented 7 years ago

(Version: current master, UK configuration and data, brand new install.)

Something (and I am unable to tell exactly what, sorry) causes the front-and-centre postcode lookup form POSTed to mapit.views.postcodes.postcode to fail, and redirect incorrectly to a 404 for

http://mapithost.domain.tld/postcode/mapit.views.postcodes.postcode

Possibly a missing reverse() function on the urlconf?

handelaar commented 7 years ago

(I hasten to add that I in no way actually need that page to work, but I figure it wants logging.)

handelaar commented 7 years ago
Page not found (404)
Request Method: GET
Request URL:    http://mapit/postcode/mapit.views.postcodes.postcode
Using the URLconf defined in project.urls, Django tried these URL patterns, in this order:
^ ^$ [name='mapit_index']
^ ^licensing$
^ ^overview$
^ ^generations(?:\.(?P<format>html|json))?$ [name='mapit_generations']
^ ^postcode/$
^ ^postcode/(?P<postcode>[A-Za-z0-9 +]+)(?:\.(?P<format>html|json))?$ [name='mapit-postcode']
^ ^postcode/partial/(?P<postcode>[A-Za-z0-9 ]+)(?:\.(?P<format>html|json))?$ [name='mapit-postcode-partial']
^ ^area/(?P<area_id>[0-9A-Z]+)(?:\.(?P<format>html|json))?$ [name='area']
^ ^area/(?P<area_id>[0-9]+)/example_postcode(?:\.(?P<format>html|json))?$
^ ^area/(?P<area_id>[0-9]+)/children(?:\.(?P<format>html|json))?$
^ ^area/(?P<area_id>[0-9]+)/geometry$
^ ^area/(?P<area_id>[0-9]+)/touches(?:\.(?P<format>html|json))?$
^ ^area/(?P<area_id>[0-9]+)/overlaps(?:\.(?P<format>html|json))?$
^ ^area/(?P<area_id>[0-9]+)/covers(?:\.(?P<format>html|json))?$
^ ^area/(?P<area_id>[0-9]+)/covered(?:\.(?P<format>html|json))?$
^ ^area/(?P<area_id>[0-9]+)/coverlaps(?:\.(?P<format>html|json))?$
^ ^area/(?P<area_id>[0-9]+)/intersects(?:\.(?P<format>html|json))?$
^ ^area/(?P<area_id>[0-9A-Z]+)\.(?P<format>kml|geojson|wkt)$ [name='area_polygon']
^ ^area/(?P<srid>[0-9]+)/(?P<area_id>[0-9]+)\.(?P<format>kml|json|geojson|wkt)$
^ ^point/$
^ ^point/(?P<srid>[0-9]+)/(?P<x>-?\d*\.?\d+),(?P<y>-?\d*\.?\d+)(?:/(?P<bb>box))?(?:\.(?P<format>html|json))?$ [name='areas-by-point']
^ ^point/latlon/(?P<lat>-?\d*\.?\d+),(?P<lon>-?\d*\.?\d+)(?:/(?P<bb>box))?(?:\.(?P<format>html|json))?$ [name='areas-by-point-latlon']
^ ^point/osgb/(?P<e>-?\d*\.?\d+),(?P<n>-?\d*\.?\d+)(?:/(?P<bb>box))?(?:\.(?P<format>html|json))?$ [name='areas-by-point-osgb']
^ ^nearest/(?P<srid>[0-9]+)/(?P<x>-?\d*\.?\d+),(?P<y>-?\d*\.?\d+)(?:\.(?P<format>html|json))?$
^ ^areas/(?P<area_ids>[0-9]+(?:,[0-9]+)*)(?:\.(?P<format>html|json))?$
^ ^areas/(?P<area_ids>[0-9]+(?:,[0-9]+)*)\.(?P<format>kml|geojson)$
^ ^areas/(?P<srid>[0-9]+)/(?P<area_ids>[0-9]+(?:,[0-9]+)*)\.(?P<format>kml|geojson)$
^ ^areas/(?P<area_ids>[0-9]+(?:,[0-9]+)*)/geometry$
^ ^areas/(?P<type>[A-Z0-9,]*[A-Z0-9]+)(?:\.(?P<format>html|json))?$
^ ^areas/(?P<name>.+?)(?:\.(?P<format>html|json))?$
^ ^areas$
^ ^code/(?P<code_type>[^/]+)/(?P<code_value>[^/]+?)(?:\.(?P<format>html|json))?$
^admin/
The current URL, postcode/mapit.views.postcodes.postcode, didn't match any of these.
dracos commented 7 years ago

That code does work on mapit.mysociety.org:

§ curl -v -d pc=B24QA https://mapit.mysociety.org/postcode/
[…]
< Location: https://mapit.mysociety.org/postcode/B24QA.html

Ah, if you include a non-alphanumeric/space character, then the reverse of 'mapit.views.postcodes.postcode' fails, and so what you see happens:

§ curl -v -d pc=B24QA. https://mapit.mysociety.org/postcode/
[…]
< Location: https://mapit.mysociety.org/postcode/mapit.views.postcodes.postcode

We should strip those characters first, presumably.

handelaar commented 7 years ago

3-line patch submitted for review

handelaar commented 7 years ago

OK yes, just changing the one problematic line is a better (and also functional) solution. :)

dracos commented 7 years ago

Thanks for spotting!