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

316 use etnservice as a dependency and drop sql helpers #317

Open
wants to merge 23 commits into
base: v2.3.1
Choose a base branch
from

Conversation

PietrH
Copy link
Member

@PietrH PietrH commented Sep 27, 2024

  • update from v2.3
  • add patch note to NEWS
  • remove sql helpers
  • check if experimental code is replaced by more general helper

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 in etnservice 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.

API - SQL mismatch

mismatches for:

  • get_cpod_projects
  • list_animal_project_codes
  • list_acoustic_project_codes
  • get_animals
  • list_receiver_ids
  • get_tags
  • get_animal_projects
  • list_scientific_names
  • get_acoustic_projects

get_cpod_projects

[1] "get_cpod_projects"
Error: `api_result` (`actual`) not identical to `sql_result` (`expected`).

`actual$moratorium` is a character vector ('0', '1', '1', '1', '0', ...)
`expected$moratorium` is a logical vector (FALSE, TRUE, TRUE, TRUE, FALSE, ...)

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

@PietrH PietrH added this to the v2.3.1 milestone Oct 4, 2024
@PietrH PietrH force-pushed the 316-use-etnservice-as-a-dependency-and-drop-_sql-helpers branch from 0e15606 to ad753e0 Compare October 4, 2024 09:55
…s' of github.com:inbo/etn into 316-use-etnservice-as-a-dependency-and-drop-_sql-helpers
@PietrH PietrH changed the base branch from v2.3 to v2.3.1 October 18, 2024 07:09
@PietrH PietrH linked an issue Oct 18, 2024 that may be closed by this pull request
@PietrH PietrH added the API label Oct 18, 2024
@PietrH
Copy link
Member Author

PietrH commented Oct 18, 2024

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?)

@peterdesmet
Copy link
Member

Maybe this is a good use case for a custom expectation.

For example, you could create a expect_call_agnostic(), with one argument: a function call. The helper could grab the function call (and its arguments), run it locally and over API and expect the result to be the same.

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"))
})

@PietrH
Copy link
Member Author

PietrH commented Oct 18, 2024

That sounds great! Do you think we should include that here, or rather as a separate PR?

@PietrH
Copy link
Member Author

PietrH commented Oct 18, 2024

9 functions currently fail to return the same result over the api as over a local connection.

@peterdesmet
Copy link
Member

That sounds great! Do you think we should include that here, or rather as a separate PR?

I'll leave that to you

@PietrH
Copy link
Member Author

PietrH commented Oct 18, 2024

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 etn and etnservice in sync much much easier 🌻

@PietrH
Copy link
Member Author

PietrH commented Oct 22, 2024

I have dropped a number of dependencies and helpers that are now unused (they were moved to etnservice)

Copy link
Member

@peterdesmet peterdesmet left a 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.

@@ -1,6 +1,6 @@
Package: etn
Title: Access Data from the European Tracking Network
Version: 2.3.0
Version: 2.3.1.9000
Copy link
Member

Choose a reason for hiding this comment

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

Don't update the version number until release. It should stay <latest-release>.9000 (so 2.2.1.9000). See #334

@@ -1,3 +1,6 @@
# etn 2.3.1
Copy link
Member

Choose a reason for hiding this comment

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

Since 2.3.0 has not been released, I would include this change in 2.3.0

@@ -1,3 +1,6 @@
# etn 2.3.1
* etn now uses a more direct dependency on `{etnservice}` for queries to a local database connection. Queries via the API and on the Lifewatch RStudio Server will now always return the same results.
Copy link
Member

Choose a reason for hiding this comment

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

Please integrate the text in the section below: maybe it's only necessary that API and R Studio will return the same results.

@@ -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"),
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants