-
Notifications
You must be signed in to change notification settings - Fork 5
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
316 use etnservice as a dependency and drop sql helpers #317
base: v2.3.1
Are you sure you want to change the base?
316 use etnservice as a dependency and drop sql helpers #317
Conversation
0e15606
to
ad753e0
Compare
…s' of github.com:inbo/etn into 316-use-etnservice-as-a-dependency-and-drop-_sql-helpers
Should we have a seperate test file that checks if the API and SQL return the same results? Or should these tests be included in the function test files? I'm quite tempted to use: for(function_to_test in getNamespaceExports("etnservice")) {
test_that(paste(
function_to_test,
"returns same result over api as over local db connection"
),
{
skip_if_offline()
api_result <- do.call(function_to_test, list(api = TRUE))
sql_result <- do.call(function_to_test, list(api = FALSE))
expect_identical(api_result, sql_result, label = function_to_test)
})
}
But not all functions run without arguments (returned objects too large?) |
Maybe this is a good use case for a custom expectation. For example, you could create a It could then be called as part of a regular test-function.R file: testthat("get_animals() returns same result locally and via API", {
expect_call_agnostic(get_animals(animal_id = "5"))
}) |
That sounds great! Do you think we should include that here, or rather as a separate PR? |
9 functions currently fail to return the same result over the api as over a local connection. |
I'll leave that to you |
Ready for review, this is a merge to the next release branch. There will be R CMD Check errors due to a mismatch between the API and SQL returned results, apart from that, it should work! Quite a nice reduction, this will make keeping |
Remove indirect dependencies
I have dropped a number of dependencies and helpers that are now unused (they were moved to etnservice) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice cleanup. Some minor suggestions in comments.
R/utils.R
Outdated
@@ -376,36 +323,12 @@ conduct_parent_to_helpers <- function(api, | |||
...) | |||
) | |||
} else { | |||
out <- do.call(glue::glue("{function_identity}_sql"), arguments_to_pass) | |||
out <- do.call(utils::getFromNamespace(function_identity, ns = "etnservice"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would argue that some of the functions in utils.R
are that big and crucial that they should be moved to their own file, e.g. conduct_parent_to_helpers.R
. Doesn't necessarily need to be tackled in this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. How do you feel about keeping the api helpers (eg. get_val()
together? They are pretty small but feel separate from other helpers (eg. check_value()
).
I'm 50/50 about creating a api_helpers.R
and keeping them together, but separate from other helpers so it's easier to differentiate for new readers what helper functions interact with the API only. I do test them together already in test-api_helpers.R
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good to keep API helpers together. I would name the file utils-api.R
or utils-api_helpers.R
, cf. how usethis::use_pipe()
creates a utils-pipe.R
https: //github.com//pull/317#discussion_r1816704543 Co-Authored-By: Peter Desmet <[email protected]>
Co-Authored-By: Peter Desmet <[email protected]>
This is going to take more work than I want to tackle in this PR, so I'll leave it like it is here. Issue #330 |
https: //github.com//pull/317#discussion_r1816719227 Co-Authored-By: Peter Desmet <[email protected]>
When I first started working on this, I didn't implement the changes to the helper immediately, but rather experimented in a single function: b03e88f, later on I moved this change to the
forward_to_api()
helper, meaning that a lot of lines can be removed. All this code still exists of course, just inetnservice
instead of here as a duplicate.From this PR onward, the API and local database connection should always return exactly the same result, any differences resulting from unintended type parsing should be considered a bug.
It seems not all the changes from v2.3 are present in this branch, namely the vignettes.
remove unused dependencies -> indirect, now moved tomoved to issue v2.3.1: remove dependencies that have now become indirect viaetnservice
etnservice
#331API - SQL mismatch
mismatches for:
get_cpod_projects
list_animal_ids: missing animal ID
56314 known id is missing from both the API and SQL result, I've sent an email to Claudia