Skip to content

Fix NULL handling in export workflow to prevent Antarctica subregion_id conversion from NULL to 0#1067

Merged
dr5hn merged 3 commits intomasterfrom
copilot/fix-971
Aug 6, 2025
Merged

Fix NULL handling in export workflow to prevent Antarctica subregion_id conversion from NULL to 0#1067
dr5hn merged 3 commits intomasterfrom
copilot/fix-971

Conversation

Copy link
Contributor

Copilot AI commented Aug 6, 2025

Antarctica does not belong to any specific subregion and should have a subregion_id of NULL. However, the export workflow was incorrectly converting NULL values to 0 during the JSON export process, which then propagated to all other data formats (CSV, SQL Server, etc.).

Root Cause

The issue was in /bin/Commands/ExportJson.php where PHP was casting NULL database values to integers:

$countriesArray[$m]['subregion_id'] = (int)$row['subregion_id']; // NULL becomes 0

Solution

Fixed the NULL handling by checking for NULL values before casting:

$countriesArray[$m]['subregion_id'] = $row['subregion_id'] !== null ? (int)$row['subregion_id'] : null;

This ensures that when the workflow regenerates the data formats, Antarctica's subregion_id will be properly exported as:

  • NULL in SQL files
  • null in JSON files
  • Empty field in CSV files
  • NULL in SQL Server files

The fix also applies to region_id to prevent similar issues with any countries that might have NULL region values.

Fixes #971.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Co-authored-by: dr5hn <6929121+dr5hn@users.noreply.github.com>
Copilot AI changed the title [WIP] Antarctica does not belong to any specific region or subregion in the traditional sense used for countries. Fix Antarctica subregion_id from 0 to null in data formats Aug 6, 2025
Copilot AI requested a review from dr5hn August 6, 2025 09:20
@dr5hn
Copy link
Owner

dr5hn commented Aug 6, 2025

@copilot The process is we update sql/world.sql file and then generate other formats via github action workflow. so somewhere in that workflow or converter it's adding 0 instead of null.

Co-authored-by: dr5hn <6929121+dr5hn@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Aug 6, 2025

@copilot The process is we update sql/world.sql file and then generate other formats via github action workflow. so somewhere in that workflow or converter it's adding 0 instead of null.

You're absolutely right! I found the issue in the workflow converter. The problem was in /bin/Commands/ExportJson.php where (int)$row['subregion_id'] was casting NULL values to 0.

I've fixed it by properly handling NULL values:

$row['subregion_id'] !== null ? (int)$row['subregion_id'] : null

The fix is in commit a836bcb. Now when the workflow runs, it should properly export Antarctica's subregion_id as null instead of 0 in all formats.

Copilot AI changed the title Fix Antarctica subregion_id from 0 to null in data formats Fix NULL handling in export workflow to prevent Antarctica subregion_id conversion from NULL to 0 Aug 6, 2025
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Aug 6, 2025
@dr5hn dr5hn marked this pull request as ready for review August 6, 2025 09:58
@dosubot dosubot bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Aug 6, 2025
@dosubot dosubot bot added the fixed Issue has been fixed label Aug 6, 2025
@dr5hn dr5hn merged commit 7fc94fd into master Aug 6, 2025
@dr5hn dr5hn deleted the copilot/fix-971 branch August 6, 2025 09:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fixed Issue has been fixed lgtm This PR has been approved by a maintainer size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Antarctica does not belong to any specific region or subregion in the traditional sense used for countries.

2 participants