Skip to content

fix: Ensure GPKG metadata consistency in test for GDAL 3.10+#740

Merged
paleolimbot merged 1 commit into
apache:mainfrom
Kontinuation:fix-gdal-gpkg-test-fail-3-10
Mar 28, 2026
Merged

fix: Ensure GPKG metadata consistency in test for GDAL 3.10+#740
paleolimbot merged 1 commit into
apache:mainfrom
Kontinuation:fix-gdal-gpkg-test-fail-3-10

Conversation

@Kontinuation
Copy link
Copy Markdown
Member

@Kontinuation Kontinuation commented Mar 28, 2026

Summary

This PR fixes the failing vector::layer::tests::test_layer_iteration_and_reset test in sedona-gdal for GDAL 3.10+. I encountered this test failure on Fedora Asahi Remix release 42.

Root Cause

The test failure is rooted in a change introduced in GDAL 3.10.0 (specifically commit f7224b4c60f7).

  • In GDAL 3.8, a newly created GPKG layer is inserted into gpkg_ogr_contents with feature_count = NULL.
  • In GDAL 3.10+, after GDAL commit 0ea26b22cd0f01689bfd94263331ffc694112a80 (backported to release/3.10 as f7224b4c60f74fc9076f37141b65ec71f8a4102f, PR #11275, issue #11274), a newly created layer is inserted with feature_count = 0.

Because OGRGeoPackageTableLayer::GetFeatureCount() first consults gpkg_ogr_contents, this changes behavior materially:

  • NULL means "unknown", so GDAL falls back to SELECT COUNT(*) FROM table.
  • 0 is treated as a valid cached count, so GDAL returns 0 immediately.

In our test, that means:

  • the second read-only dataset can already iterate the 3 inserted features;
  • but feature_count(true) returns the stale cached metadata value 0.

So the mismatch is specifically: feature iteration sees the rows, but GetFeatureCount() trusts stale metadata.

Implementation

By explicitly drop(dataset)ing the writer before opening the reader, we trigger GDALClose, which commits all features and accurately updates the gpkg_ogr_contents metadata to 3. This approach ensures consistent test results across all GDAL versions by respecting transactional visibility.

@github-actions github-actions Bot requested a review from paleolimbot March 28, 2026 14:50
This fix explicitly drops the writer dataset before opening a reader
connection in test_layer_iteration_and_reset.

GDAL 3.10+ (via commit f7224b4c60f7) changed metadata initialization
for GPKG from feature_count = NULL to feature_count = 0. Since the
reader in this test uses a separate connection, it would see the
stale '0' value because the writer's implicit transaction hadn't been
flushed or committed yet. Trusting this non-negative value is a GDAL
optimization that resulted in the reader reporting 0 features.

Closing the writer ensures all features are committed and the
gpkg_ogr_contents metadata is correctly updated to 3.
@Kontinuation Kontinuation force-pushed the fix-gdal-gpkg-test-fail-3-10 branch from fc114e3 to 4b328ad Compare March 28, 2026 14:54
@Kontinuation Kontinuation marked this pull request as ready for review March 28, 2026 15:40
Copy link
Copy Markdown
Member

@paleolimbot paleolimbot left a comment

Choose a reason for hiding this comment

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

Thank you!

@paleolimbot paleolimbot merged commit 0163a6b into apache:main Mar 28, 2026
17 checks passed
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.

2 participants