Fix typo breaking st_as_sfc.pq_geometry() on every input - #2626
Merged
Merged
Conversation
st_as_sfc.pq_geometry() forwards to st_as_sfc.WKB() using the argument name "spatiallite", which doesn't match st_as_sfc.WKB()'s actual "spatialite" parameter. The unmatched named argument falls through st_as_sfc.WKB()'s own `...` and rides along into its final st_sfc(ret, ...) call, where sfc_unique_sfg_dims_and_types() trips over it and fails with a misleading "object(s) should be of class 'sfg'" -- unrelated to the actual geometry being converted. This means st_as_sfc() has been broken for every pq_geometry input (i.e. every PostGIS geometry column read via RPostgres::dbGetQuery(), the exact workflow r-spatial#1195 introduced this method for) since that method was added -- the typo was already present in the fix suggested there. Fixes r-spatial#2625.
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.
Fixes #2625.
Summary
st_as_sfc.pq_geometry()(R/db.R) forwards tost_as_sfc.WKB()using the argument namespatiallite, which doesn't matchst_as_sfc.WKB()'s actualspatialiteparameter. The unmatched named argument falls throughst_as_sfc.WKB()'s own...and rides along into its finalst_sfc(ret, ...)call, wheresfc_unique_sfg_dims_and_types()trips over it and fails with a misleading"object(s) should be of class 'sfg'"— unrelated to the actual geometry being converted.This means
st_as_sfc()has been broken for everypq_geometryinput — i.e. every PostGIS geometry column read viaRPostgres::dbGetQuery(), the exact workflow #1195 introduced this method for — since that method was added. The typo was already present in the fix suggested in that issue and appears to have been merged verbatim.Why this was dormant until 1.1-3
The typo itself has been there since #1195 (2019), but it was harmless for years: in 1.1-2,
st_as_sfc.WKB()'s final calls did not forward...intost_sfc()at all —— so any stray/unmatched argument (including the mistyped
spatiallite) was silently dropped and never reachedst_sfc().1.1-3 changed this in
R/wkb.Rto forward...through:That's commit a264e6f ("1.1-3 CRAN submission"), landed alongside #2622's
precision=round-trip work forst_coordinates()— almost certainly to let callers passst_sfc()-level args likeprecisionthroughst_as_sfc(). Reasonable on its own, but it's what first gave the six-year-old typo an actual path to break something: now the strayspatiallite = FALSErides along in...straight intost_sfc()'ssfg-class validation.Confirmed directly against the CRAN source tarballs for both versions (
R/wkb.Rdiff, 1.1-2 → 1.1-3 is exactly the two lines above) and reproduced the crash appearing/disappearing across a clean reinstall of each release.Fix
One-character rename,
spatiallite→spatialite, so the argument actually reachesst_as_sfc.WKB()'s matching formal instead of leaking through....Test plan
tests/testthat/test-wkb.Rreusing the existing WKB hex fixture from that file, just re-classed as"pq_geometry".devtools::load_all()+testthat::test_file()):st_as_sfc.pq_geometry→st_as_sfc.WKB→st_sfc→sfc_unique_sfg_dims_and_types.test-wkb.Rpasses in full.R/wkb.Rdiff above.Related
...intost_sfc(), surfacing the dormant typo.