Skip to content

Commit 800a462

Browse files
committed
fix api failing tests and update documentation
1 parent 2cc9fb1 commit 800a462

File tree

3 files changed

+73
-16
lines changed

3 files changed

+73
-16
lines changed

api/tests/test_utils/db_utils.py

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -192,23 +192,14 @@ def is_test_db(url):
192192

193193
def empty_database(db, url):
194194
if is_test_db(url):
195-
196-
metadata_tables = Base.metadata.tables
197-
198-
# Get all table names excluding those in the excluded_tables list
199-
all_table_names = [table_name for table_name in metadata_tables.keys() if table_name not in excluded_tables]
200-
201-
# Sort the table names in reverse order of dependencies
202-
tables_to_delete = sorted(
203-
all_table_names, key=lambda name: len(metadata_tables[name].foreign_keys), reverse=True
204-
)
205-
206195
try:
207196
with db.start_db_session() as session:
208-
for table_name in tables_to_delete:
209-
table = Base.metadata.tables[table_name]
210-
delete_stmt = delete(table)
211-
session.execute(delete_stmt)
212-
197+
# Using sorted_tables to respect foreign key constraints
198+
for table in reversed(Base.metadata.sorted_tables):
199+
if table.name not in excluded_tables:
200+
table = Base.metadata.tables[table.name]
201+
delete_stmt = delete(table)
202+
session.execute(delete_stmt)
203+
session.commit()
213204
except Exception as error:
214205
logging.error(f"Error while deleting from test db: {error}")

functions-python/tasks_executor/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,14 @@ To get the list of supported tasks use:
5050
"payload": {}
5151
}
5252
```
53+
To update the geolocation files precision:
54+
```json
55+
{
56+
"task": "update_geojson_files_precision",
57+
"payload": {
58+
"dry_run": true,
59+
"precision": 5,
60+
"limit": 10
61+
}
62+
}
63+
```
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Update GeoJSON files
2+
3+
This task adjust the GeoJSON files removing the map IDs and reducing the precision of the coordinates to 5 decimal places. ALso updates the geolocation_file_created_date and geolocation_file_dataset_id fields in the Feed table.
4+
5+
---
6+
7+
## Task ID
8+
9+
Use task ID: `update_geojson_files_precision`
10+
11+
---
12+
13+
## Usage
14+
15+
The function accepts the following payload:
16+
17+
```json
18+
{
19+
"dry_run": true, // [optional] If true, do not upload or modify the database (default: true)
20+
"precision": 5, // [optional] Number of decimal places to keep in coordinates (default: 5)
21+
"limit": 10 // [optional] Limit the number of feeds to process (default: no limit)
22+
}
23+
```
24+
25+
### Example:
26+
27+
```json
28+
{
29+
"dry_run": true,
30+
"limit": 10
31+
}
32+
```
33+
34+
---
35+
36+
## What It Does
37+
38+
List all feeds with GeoJSON files, download each file, remove map IDs, reduce coordinate precision to the specified number of decimal places, and re-upload the modified file.
39+
Also updates the `geolocation_file_created_date` and `geolocation_file_dataset_id` fields in the `Feed` table.
40+
41+
## GCP Environment Variables
42+
43+
The function requires the following environment variables:
44+
45+
| Variable | Description |
46+
| ---------------------- | ---------------------------------------------------------------------------- |
47+
| `DATASETS_BUCKET_NAME` | The name of the GCS bucket used to store extracted GTFS files |
48+
49+
---
50+
51+
## Additional Notes
52+
53+
* Commits to the database occur in batches of 100 feeds to improve performance and avoid large transaction blocks.
54+
* If `dry_run` is enabled, files are uploads or DB modifications are performed. Only the number of affected feeds is logged.
55+
* The function is safe to rerun. It will only affect feeds with missing geolocation_file_dataset_id.

0 commit comments

Comments
 (0)