Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions R/get_ogc_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,14 @@ switch_properties_id <- function(properties, id) {
}

if (length(properties) == 0) {
# If a user requested only id and/or geometry, properties would now be empty
# geometry is taken care of with skipGeometry
properties <- "id"
# If a user requested only id and/or geometry, properties is now empty.
# The feature "id" always comes back (and geometry is handled by
# skipGeometry), so omit the properties filter entirely rather than
# requesting "id": several collections (e.g. daily, continuous) now
# reject "id" as a selectable property, and it also fails the
# available-properties check below. rejigger_cols() still subsets the
# result to the requested id column.
properties <- NA_character_
}
}

Expand Down
32 changes: 32 additions & 0 deletions tests/testthat/tests_general.R
Original file line number Diff line number Diff line change
Expand Up @@ -648,3 +648,35 @@ test_that("format_dates", {
"2025-10-01/2026-02-02"
)
})

test_that("switch_properties_id drops id and geometry from the wire properties", {
# The feature "id" always comes back (renamed to the service id
# downstream) and several collections (e.g. daily, continuous) now reject
# "id" as a selectable property, so it must never be sent. A request for
# only id and/or geometry must omit the properties filter (NA), not fall
# back to "id".
expect_true(all(is.na(
dataRetrieval:::switch_properties_id("daily_id", id = "daily_id")
)))
expect_true(all(is.na(
dataRetrieval:::switch_properties_id("id", id = "daily_id")
)))
expect_true(all(is.na(
dataRetrieval:::switch_properties_id(c("daily_id", "geometry"), id = "daily_id")
)))

# Mixed requests: the id alias and geometry are dropped, real properties kept.
expect_equal(
dataRetrieval:::switch_properties_id(c("daily_id", "value"), id = "daily_id"),
"value"
)
expect_equal(
dataRetrieval:::switch_properties_id(c("id", "value", "geometry"), id = "daily_id"),
"value"
)

# No properties requested -> unchanged (NA passes through).
expect_true(all(is.na(
dataRetrieval:::switch_properties_id(NA, id = "daily_id")
)))
})
Loading