]> git.openstreetmap.org Git - nominatim.git/commitdiff
avoid forwarding variables via SQL
authorSarah Hoffmann <lonvia@denofr.de>
Wed, 12 Jul 2023 12:04:30 +0000 (14:04 +0200)
committerSarah Hoffmann <lonvia@denofr.de>
Fri, 14 Jul 2023 13:27:16 +0000 (15:27 +0200)
nominatim/api/results.py
nominatim/api/reverse.py

index 2fe547112b07e16932b2d5d84243bf816fb7ef30..d425ff6cbad94665984c1c086ad9c3d570cf707a 100644 (file)
@@ -302,7 +302,9 @@ def create_from_osmline_row(row: Optional[SaRow],
 
 
 def create_from_tiger_row(row: Optional[SaRow],
-                          class_type: Type[BaseResultT]) -> Optional[BaseResultT]:
+                          class_type: Type[BaseResultT],
+                          osm_type: Optional[str] = None,
+                          osm_id: Optional[int] = None) -> Optional[BaseResultT]:
     """ Construct a new result and add the data from the result row
         from the Tiger data interpolation table. 'class_type' defines
         the type of result to return. Returns None if the row is None.
@@ -317,7 +319,7 @@ def create_from_tiger_row(row: Optional[SaRow],
 
     res = class_type(source_table=SourceTable.TIGER,
                      place_id=row.place_id,
-                     osm_object=(row.osm_type, row.osm_id),
+                     osm_object=(osm_type or row.osm_type, osm_id or row.osm_id),
                      category=('place', 'houses' if hnr is None else 'house'),
                      postcode=row.postcode,
                      country_code='us',
index 38f993be549f12b997dc1d90a39e53d44cd2af9e..6a76becd9504ba1d828f3d02e77afe5dbc3fc649 100644 (file)
@@ -7,7 +7,8 @@
 """
 Implementation of reverse geocoding.
 """
-from typing import Optional, List, Callable, Type, Tuple, Dict, Any
+from typing import Optional, List, Callable, Type, Tuple, Dict, Any, cast
+import functools
 
 import sqlalchemy as sa
 
@@ -270,9 +271,7 @@ class ReverseGeocoder:
         return (await self.conn.execute(sql, self.bind_params)).one_or_none()
 
 
-    async def _find_tiger_number_for_street(self, parent_place_id: int,
-                                            parent_type: str,
-                                            parent_id: int) -> Optional[SaRow]:
+    async def _find_tiger_number_for_street(self, parent_place_id: int) -> Optional[SaRow]:
         t = self.conn.t.tiger
 
         def _base_query() -> SaSelect:
@@ -287,8 +286,6 @@ class ReverseGeocoder:
 
             return sa.select(inner.c.place_id,
                              inner.c.parent_place_id,
-                             sa.sql.expression.label('osm_type', parent_type),
-                             sa.sql.expression.label('osm_id', parent_id),
                              _interpolated_housenumber(inner),
                              _interpolated_position(inner),
                              inner.c.postcode,
@@ -332,14 +329,15 @@ class ReverseGeocoder:
                     distance = addr_row.distance
                 elif row.country_code == 'us' and parent_place_id is not None:
                     log().comment('Find TIGER housenumber for street')
-                    addr_row = await self._find_tiger_number_for_street(parent_place_id,
-                                                                        row.osm_type,
-                                                                        row.osm_id)
+                    addr_row = await self._find_tiger_number_for_street(parent_place_id)
                     log().var_dump('Result (street Tiger housenumber)', addr_row)
 
                     if addr_row is not None:
+                        row_func = cast(RowFunc,
+                                        functools.partial(nres.create_from_tiger_row,
+                                                          osm_type=row.osm_type,
+                                                          osm_id=row.osm_id))
                         row = addr_row
-                        row_func = nres.create_from_tiger_row
             else:
                 distance = row.distance