Skip to content

Commit 7b02c25

Browse files
committed
Fix get sql timestamp
1 parent e700d77 commit 7b02c25

File tree

4 files changed

+30
-16
lines changed

4 files changed

+30
-16
lines changed

functions-python/helpers/locations.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def get_country_code(country_name: str) -> Optional[str]:
3535
Optional[str]: Two-letter ISO country code or None if not found
3636
"""
3737
import pycountry
38+
3839
# Return None for empty or whitespace-only strings
3940
if not country_name or not country_name.strip():
4041
logging.error("Could not find country code for: empty string")

functions-python/tasks_executor/src/tasks/geojson/update_geojson_files_precision.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import re
2121
from typing import Any, Dict, List
2222

23+
from sqlalchemy import select, func
24+
2325
from shared.database.database import with_db_session
2426
from shared.database_gen.sqlacodegen_models import Gtfsfeed
2527
from shared.helpers.locations import round_geojson_coords
@@ -151,7 +153,7 @@ def update_geojson_files_precision_handler(
151153

152154
feeds: [Gtfsfeed] = query_unprocessed_feeds(limit, db_session)
153155
logging.info("Found %s feeds", len(feeds))
154-
timestamp = db_session.execute("SELECT CURRENT_TIMESTAMP").scalar()
156+
timestamp = db_session.execute(select(func.current_timestamp())).scalar()
155157
for feed in feeds:
156158
try:
157159
if processed % 100 == 0:

functions-python/tasks_executor/tests/conftest.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,6 @@
1414
# limitations under the License.
1515
#
1616

17-
from pathlib import Path
18-
import sys
19-
20-
# Ensure project's src is on sys.path so imports like 'shared' resolve when tests start
21-
_repo_root = Path(__file__).resolve().parents[1]
22-
_src_dir = str(_repo_root / "src")
23-
if _src_dir not in sys.path:
24-
sys.path.insert(0, _src_dir)
25-
2617
from datetime import datetime, UTC, timedelta
2718

2819
from sqlalchemy.orm import Session

functions-python/tasks_executor/tests/tasks/geojson/test_update_geojson_files_precision.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,10 @@ def test_process_geojson_round_and_remove_osm_keys(self):
8181
"features": [
8282
{
8383
"type": "Feature",
84-
"geometry": {"type": "Point", "coordinates": [12.3456789, -98.7654321]},
84+
"geometry": {
85+
"type": "Point",
86+
"coordinates": [12.3456789, -98.7654321],
87+
},
8588
"properties": {
8689
"name": "A",
8790
"osm_id": 123,
@@ -113,13 +116,18 @@ def test_process_geojson_single_feature_and_list_variants(self):
113116
}
114117
out1 = process_geojson(feat, precision=4)
115118
self.assertIsInstance(out1, dict)
116-
self.assertEqual(out1["geometry"]["coordinates"], [round(1.23456789, 4), round(2.3456789, 4)])
119+
self.assertEqual(
120+
out1["geometry"]["coordinates"], [round(1.23456789, 4), round(2.3456789, 4)]
121+
)
117122
self.assertNotIn("osm", out1.get("properties", {}))
118123

119124
lst = [feat]
120125
out2 = process_geojson(lst, precision=3)
121126
self.assertIsInstance(out2, list)
122-
self.assertEqual(out2[0]["geometry"]["coordinates"], [round(1.23456789, 3), round(2.3456789, 3)])
127+
self.assertEqual(
128+
out2[0]["geometry"]["coordinates"],
129+
[round(1.23456789, 3), round(2.3456789, 3)],
130+
)
123131

124132
@patch("tasks.geojson.update_geojson_files_precision.query_unprocessed_feeds")
125133
def test_handler_uploads_and_updates_feed_info(self, mock_query):
@@ -128,7 +136,10 @@ def test_handler_uploads_and_updates_feed_info(self, mock_query):
128136
"features": [
129137
{
130138
"type": "Feature",
131-
"geometry": {"type": "Point", "coordinates": [100.1234567, 0.9876543]},
139+
"geometry": {
140+
"type": "Point",
141+
"coordinates": [100.1234567, 0.9876543],
142+
},
132143
"properties": {"id": "node/1", "keep": "x"},
133144
}
134145
],
@@ -149,7 +160,11 @@ def test_handler_uploads_and_updates_feed_info(self, mock_query):
149160
fake_feed = types.SimpleNamespace(
150161
stable_id=feed_stable_id,
151162
geolocation_file_created_date=None,
152-
gtfsdatasets=[types.SimpleNamespace(bounding_box=types.SimpleNamespace(id="bbid"), downloaded_date=None)],
163+
gtfsdatasets=[
164+
types.SimpleNamespace(
165+
bounding_box=types.SimpleNamespace(id="bbid"), downloaded_date=None
166+
)
167+
],
153168
)
154169

155170
mock_query.return_value = [fake_feed]
@@ -168,7 +183,12 @@ def commit(self):
168183

169184
fake_db = FakeDBSession()
170185

171-
payload = {"bucket_name": "any-bucket", "dry_run": False, "precision": 5, "limit": 1}
186+
payload = {
187+
"bucket_name": "any-bucket",
188+
"dry_run": False,
189+
"precision": 5,
190+
"limit": 1,
191+
}
172192

173193
# Inject modules into sys.modules for the duration of the handler call
174194
with patch.dict(sys.modules, {"google.cloud": cloud_mod, "google": google_mod}):

0 commit comments

Comments
 (0)