fix(spp_area_hdx): derive ISO3 code from hdx_dataset_id#14
fix(spp_area_hdx): derive ISO3 code from hdx_dataset_id#14
Conversation
Summary of ChangesHello @emjay0921, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a critical issue where the HDX synchronization process failed for countries without a pre-configured Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request effectively fixes a bug where incorrect 2-letter ISO codes were used to construct HDX dataset IDs, leading to synchronization failures. The solution is well-implemented: it correctly derives the 3-letter ISO code from hdx_dataset_id when available and smartly updates the sync logic to use the dataset ID directly, bypassing the problematic code path. The changes are clear and directly address the root cause. I have one minor suggestion to improve code maintainability.
| for record in self: | ||
| if record.country_id: | ||
| if record.hdx_dataset_id and record.hdx_dataset_id.startswith("cod-ab-"): | ||
| record.country_iso3 = record.hdx_dataset_id[7:].upper() |
There was a problem hiding this comment.
Using the magic number 7 for slicing is brittle. It's better to derive the length from the prefix string itself. This makes the code more maintainable, as changing the prefix string in the startswith check would automatically update the slice length.
| record.country_iso3 = record.hdx_dataset_id[7:].upper() | |
| record.country_iso3 = record.hdx_dataset_id[len("cod-ab-"):].upper() |
Why is this change needed?
country_iso3computed field usedcountry_id.codewhich returns 2-letter ISO codes (PH, LK) instead of 3-letter ISO3 codes (PHL, LKA). This causedaction_sync_from_hdxto construct incorrect dataset IDs likecod-ab-phinstead ofcod-ab-phl, making the HDX sync fail for any country without a pre-configuredhdx_dataset_id.How was the change implemented?
_compute_country_iso3now derives ISO3 fromhdx_dataset_idwhen available (e.g.,cod-ab-phl→PHL), falling back tocountry_id.codefor new recordshdx_dataset_idto the@api.dependsdecorator so the field recomputes when the dataset ID is setaction_sync_from_hdxnow usesget_dataset()directly whenhdx_dataset_idis already set, avoiding the ISO3 code path entirelyNew unit tests
Unit tests executed by the author
How to test manually
hdx_dataset_id— ISO3 falls back to 2-letter code until dataset ID is setRelated links