From 37492551a4409ee84be2cfd66d7b2f613640ea93 Mon Sep 17 00:00:00 2001 From: Alex Bertram Date: Mon, 1 Jul 2024 07:58:32 +0000 Subject: [PATCH] Fix #124: Correct handling of imports with serial numbers --- R/import.R | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/R/import.R b/R/import.R index e131910..e546370 100644 --- a/R/import.R +++ b/R/import.R @@ -295,6 +295,9 @@ matchRecordIdsByKey <- function(schema, data, fieldIds, fieldValues) { keys <- which(fieldIds %in% keyFieldIds) provided <- as.data.frame(fieldValues[keys]) + if(ncol(provided) != length(keyFieldIds)) { + stop("One or more key fields are missing") + } names(provided) <- sprintf("k%d", seq_along(keyFieldIds)) # Check that our input does not include duplicates according to the key @@ -316,7 +319,7 @@ matchRecordIdsByKey <- function(schema, data, fieldIds, fieldValues) { findKeyFieldIds <- function(schema) { fieldIds <- sapply(schema$elements, function(e) e$id) - keys <- sapply(schema$elements, function(e) identical(e$key, TRUE)) + keys <- sapply(schema$elements, function(e) identical(e$key, TRUE) && e$type != "serial") return(fieldIds[keys]) }