Skip to content

fix: pmtiles generation fails with error: route_id#1373

Merged
davidgamez merged 5 commits into
mainfrom
fix/pmtiles_generation_fails_route_id
Sep 25, 2025
Merged

fix: pmtiles generation fails with error: route_id#1373
davidgamez merged 5 commits into
mainfrom
fix/pmtiles_generation_fails_route_id

Conversation

@davidgamez

@davidgamez davidgamez commented Sep 23, 2025

Copy link
Copy Markdown
Member

Summary:

Fixes #1358

This PR adds a detect_encoding function to be used by the file loaders. This makes sure the file and columns are properly loaded.
In Python, opening a UTF-8 file with encoding="utf-8" doesn’t remove a BOM if present, so the first string may contain a hidden \ufeff. Using encoding="utf-8-sig" strips the BOM automatically and avoids this issue.

A BOM (Byte Order Mark) is a special hidden character at the start of some text files that indicates the file’s encoding. In UTF-8 it isn’t needed, but some editors add it anyway.

Expected behavior:

CSV files with BOOM characters are properly read.

Testing tips:
Use the verifier with feed id mdb-733 and dataset id mdb-733-202509111637.

Please make sure these boxes are checked before submitting your pull request - thanks!

  • Run the unit tests with ./scripts/api-tests.sh to make sure you didn't break anything
  • Add or update any needed documentation to the repo
  • Format the title like "feat: [new feature short description]". Title must follow the Conventional Commit Specification(https://www.conventionalcommits.org/en/v1.0.0/).
  • Linked all relevant issues
  • Include screenshot(s) showing how this pull request works and fixes the issue(s)

@davidgamez
davidgamez requested a review from Copilot September 23, 2025 21:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes pmtiles generation failures related to route_id errors by implementing dynamic encoding detection for CSV files. The changes address issues where CSV files with different character encodings were causing parsing failures.

  • Adds encoding detection functionality using charset_normalizer library
  • Updates CSV reading operations to use detected encoding instead of hardcoded UTF-8
  • Includes comprehensive test coverage for the new encoding detection feature

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
functions-python/helpers/utils.py Adds detect_encoding function to dynamically detect file encoding
functions-python/pmtiles_builder/src/main.py Updates shapes file reading to use detected encoding
functions-python/pmtiles_builder/src/csv_cache.py Updates CSV reading to use detected encoding
functions-python/helpers/tests/test_helpers.py Adds unit tests for encoding detection functionality
functions-python/pmtiles_builder/requirements.txt Adds charset_normalizer dependency
functions-python/helpers/requirements.txt Adds charset_normalizer dependency
functions-python/pmtiles_builder/src/scripts/pmtiles_builder_verifier.py Adds new test dataset and updates feed index

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread functions-python/helpers/utils.py Outdated
Comment thread functions-python/helpers/utils.py
Comment thread functions-python/pmtiles_builder/src/csv_cache.py Outdated
davidgamez and others added 4 commits September 23, 2025 17:44
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@davidgamez
davidgamez marked this pull request as ready for review September 23, 2025 22:25

@jcpitre jcpitre left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@davidgamez
davidgamez merged commit 182e492 into main Sep 25, 2025
2 of 4 checks passed
@davidgamez
davidgamez deleted the fix/pmtiles_generation_fails_route_id branch September 25, 2025 21:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pmtiles generation fails with error: route_id

3 participants