Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only allow a single target_keys key value pair #90

Merged
merged 18 commits into from
Jan 17, 2025

Conversation

annakrystalli
Copy link
Member

@annakrystalli annakrystalli commented Dec 18, 2024

This PR resolves #89 and is related to hubverse-org/schemas#118

Specifically In v4.0.1, we are only allowing a single target_keys key value pair.

To ensure hubAdmin functionality conform to this pattern this PR:

  • [Adds a test that demonstrates correct identification of more that 1 target_keys key value pair when validating task.json files with validate_config()
  • Ensure an error is thrown when creating target_keys with more that 1 key value pair programmatically for configs using schema versions v4.0.1 and above
  • I also corrected some instances where there was a typo in the hubAdmin.branch option specification. This didn't affect tests though as it was setting it to the default value anyways.

Note: unrelated test failures still exist and will need resolving before merging Found solution @zkamvar had applied in #86 (8e8ed51) and cherry picked into here!

Copy link

github-actions bot commented Dec 18, 2024

@annakrystalli annakrystalli marked this pull request as ready for review December 18, 2024 09:49
@annakrystalli annakrystalli requested a review from elray1 December 18, 2024 09:49
"target_id": "wk ahead inc flu hosp",
"target_name": "weekly influenza hospitalization incidence",
"target_units": "rate per 100,000 population",
"target_keys": null,
Copy link
Member Author

Choose a reason for hiding this comment

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

section relevant to test

Comment on lines 145 to 148
"target_keys": {
"target": "wk flu hosp",
"target_metric": "rate change"
},
Copy link
Member Author

Choose a reason for hiding this comment

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

section relevant to tests

Comment on lines 14 to 21
#' @param target_keys named list or `NULL`. The `target_keys` value defines a
#' single target.
#' Should be `NULL`, in the case where the target is not specified as a task_id
#' but is specified solely through the `target_id` argument.
#' Otherwise, should be a named list containing a single character string element.
#' The name of the element should match a `task_id`
#' variable name within the same `model_tasks` object and the value should match
#' a single value of that variable.
Copy link
Member Author

Choose a reason for hiding this comment

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

Although in the code I only apply the restriction to configs with version v4.0.1 and greater, I've gone ahead an just updated the docs with what's allowed going forward. Otherwise I think the docs would be too complex and prehaps confusing when I don't belivee anyone was using the feature anyways.

Comment on lines 154 to 167
is_gte_v4_0_1 <- hubUtils::version_gte(
"v4.0.1",
schema_version = schema_version
)
target_key_n <- length(target_keys)
if (is_gte_v4_0_1 && target_key_n > 1L) {
cli::cli_abort(
c(
"!" = "{.arg target_keys} must be a named {.cls list} of
length {.val {1L}} not {.val {target_key_n}}."
),
call = call
)
}
Copy link
Member Author

Choose a reason for hiding this comment

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

I restricted this to the relevant versions to ensure it matches what's actually described in earlier schema

annakrystalli and others added 2 commits December 18, 2024 11:57
A weird bug just popped up and I don't know where it's coming from, but
effectively, when a value with a class of "error" is passed to
`encodeString()`, it fails with:

Error in UseMethod("conditionMessage") :
  no applicable method for 'conditionMessage' applied to an object of class "error"

This never used to happen, so I'm fixing it here.
@@ -6,7 +6,7 @@ test_that("Missing files returns an invalid config with an immediate message", {
"File does not exist"
)
})
expect_false(out)
expect_false(unclass(out))
Copy link
Member Author

Choose a reason for hiding this comment

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

Fixes new errors from changes in testthat. Cherry picked from 8e8ed51

Copy link
Contributor

@elray1 elray1 left a comment

Choose a reason for hiding this comment

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

these changes look good to me. I'm commenting rather than approving for the same reasons outlined in this comment.

Copy link
Member

@zkamvar zkamvar left a comment

Choose a reason for hiding this comment

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

This looks cromulent to me! Approving pending the bump to major version discussed in hubverse-org/schemas#118 (comment)

R/create_target_metadata_item.R Outdated Show resolved Hide resolved
R/create_target_metadata_item.R Outdated Show resolved Hide resolved
@annakrystalli annakrystalli merged commit 580cc7e into main Jan 17, 2025
8 checks passed
@annakrystalli annakrystalli deleted the ak/1-target-key-value-pair/89 branch January 17, 2025 14:43
Copy link

codecov bot commented Jan 17, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.30%. Comparing base (34f2624) to head (f04326f).
Report is 47 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #90      +/-   ##
==========================================
+ Coverage   89.25%   89.30%   +0.05%     
==========================================
  Files          30       30              
  Lines        2420     2432      +12     
==========================================
+ Hits         2160     2172      +12     
  Misses        260      260              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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.

Only allow a single target_keys key value pair to conform to v4.0.1 schema
3 participants