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

fix: task returned from content_render missing task_id #339

Merged
merged 6 commits into from
Nov 27, 2024

Conversation

toph-allen
Copy link
Collaborator

@toph-allen toph-allen commented Nov 27, 2024

Intent

Fix poll_task for tasks returned by content_render.

Fixes #338

Approach

The POST variants/{variant_id}/render endpoint returns an object that is shaped differently from the task returned by the deploy task, with the task ID named id and not task_id. Thus, when creating a VariantTask object, we need to rename the parameter.

I believe this was working in an initial draft of this functionality, but was changed in a subsequent PR that altered the return type for the function.

I added an integration test to verify content_render and the task it returns.

Checklist

  • Does this change update NEWS.md (referencing the connected issue if necessary)?
  • Does this change need documentation? Have you run devtools::document()?

@toph-allen toph-allen marked this pull request as ready for review November 27, 2024 19:01
R/deploy.R Outdated
@@ -580,7 +580,7 @@ poll_task <- function(task, wait = 1, callback = message) {
code <- -1
first <- 0
while (!finished) {
task_data <- con$task(task$get_task()$task_id, wait = wait, first = first)
task_data <- con$task(task$task$task_id, wait = wait, first = first)
Copy link
Collaborator

Choose a reason for hiding this comment

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

You don't technically need this change right? get_task() just yields self$task. (Not opposed to ripping out the unnecessary getters, but that seems better done in a separate refactor PR where you did them all.)

Copy link
Collaborator Author

@toph-allen toph-allen Nov 27, 2024

Choose a reason for hiding this comment

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

Correct, I don't technically need it; happy to revert if you think it's bad to change it here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree, for things like this which are easily greppable, no need to do it piecemeal.

R/content.R Outdated
@@ -1007,6 +1007,9 @@ content_render <- function(content, variant_key = NULL) {
target_variant <- get_variant(content, variant_key)
}
render_task <- target_variant$render()
# Tasks returned from variant render endpoint look different from those
# returned by deploy.
render_task$task_id <- render_task$id
Copy link
Collaborator

Choose a reason for hiding this comment

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

I see this same logic in the Task initialize method: https://github.com/rstudio/connectapi/blob/main/R/deploy.R#L67-L69

Why doesn't that handle this for you already?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Right, because of course VariantTask doesn't inherit from Task :/

I think the better fix would be to push this adapting into the VariantTask init method. Even better would be to look to fix the inheritance of all of these apparent (but not actual) Task subclasses, but that could be a followup--I'm not trying to derail a bugfix by tempting you into refactoring all the things.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah lol. But good point, I'll put it into VariantTask and rip out the other place that also does it.

I don't think ContentTask needs it because I don't think there are any content APIs that return this form.

Copy link
Collaborator

@nealrichardson nealrichardson left a comment

Choose a reason for hiding this comment

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

Thanks for the quick and crisp fix!

@toph-allen toph-allen merged commit 31fee40 into main Nov 27, 2024
19 checks passed
@toph-allen toph-allen deleted the toph/issue-338 branch November 27, 2024 22:05
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.

poll_task is trowing a 404 error because of changes in api reference
2 participants