fix: pmtiles generation fails with error: route_id#1373
Merged
Conversation
Contributor
There was a problem hiding this comment.
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.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
davidgamez
marked this pull request as ready for review
September 23, 2025 22:25
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
Fixes #1358
This PR adds a
detect_encodingfunction 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
BOMif 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!
./scripts/api-tests.shto make sure you didn't break anything