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

[batch] Fix list batches query and test #13237

Merged
merged 3 commits into from
Jul 12, 2023
Merged

Conversation

jigold
Copy link
Contributor

@jigold jigold commented Jul 11, 2023

The test that lists batches timed out. The main problem is the limit in the aioclient used by the test_batch tests was passing a string rather than an integer. I assumed downstream the function was passing an integer. Therefore, we were doing this:

batch_id < "137"
and not batch_id < 137.

So the query was running forever and scanning all batches from the test user.

I also was missing a tag annotation on the queries, but that was not causing the timeout.

Copy link
Contributor

@danking danking left a comment

Choose a reason for hiding this comment

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

Can you describe the problem(s)? I'm not sure what this is fixing

@jigold
Copy link
Contributor Author

jigold commented Jul 11, 2023

The test that lists batches timed out. The main problem is the limit in the aioclient used by the test_batch tests was passing a string rather than an integer. I assumed downstream the function was passing an integer. Therefore, we were doing this:

batch_id < "137"

and not batch_id < 137.

So the query was running forever and scanning all batches from the test user.

I also was missing a tag annotation on the queries, but that was not causing the timeout.

Copy link
Contributor

@danking danking left a comment

Choose a reason for hiding this comment

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

Can you edit the PR message with your comment so that when the commit merges into main we have a record of why we made this change? Thanks!

@@ -634,7 +634,11 @@ async def _query_batches(request, user: str, q: str, version: int, last_batch_id
async def get_batches_v1(request, userdata): # pylint: disable=unused-argument
Copy link
Contributor

Choose a reason for hiding this comment

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

We should fix the types so that we cannot make this mistake in the future. There's a couple things we need to do:

  1. add type annotations here: request: web.Request (userdata is a little harder to type, but maybe just Dict[str, str] for now?)
  2. Fix _handle_api_error to properly use types. It needs to use ParamSpec (see also the ParamSpec docs). This seems to type correctly and also cause mypy errors where it should:
T = TypeVar('T')
P = ParamSpec('P')

async def _handle_api_error(f: Callable[P, Awaitable[T]], *args: P.args, **kwargs: P.kwargs) -> Optional[T]:

@jigold
Copy link
Contributor Author

jigold commented Jul 12, 2023

@danking

I can keep digging, but it looks like the ParamSpec feature isn't available in the Python version we're running. I'll see if there's a workaround, but I'd really not like to hold up this change anymore than needed.

Module "typing" has no attribute "ParamSpec"; maybe "_ParamSpec"?

@jigold
Copy link
Contributor Author

jigold commented Jul 12, 2023

It looks like ParamSpec was added in 3.10

@danking
Copy link
Contributor

danking commented Jul 12, 2023

Can we use the ParamSpec from typing_extensions?

@jigold
Copy link
Contributor Author

jigold commented Jul 12, 2023

This commit looks like it's going to succeed.

@@ -227,17 +240,17 @@ async def _handle_ui_error(session, f, *args, **kwargs):
raise


async def _handle_api_error(f, *args, **kwargs):
async def _handle_api_error(f: Callable[P, Awaitable[T]], *args: P.args, **kwargs: P.kwargs) -> Optional[T]:
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be a separate PR, but these new types and all those assert ... is not None reveal another issue.

This function conflates two distinct pieces of functionality:

  1. Make functions returning no values idempotent
  2. Convert BatchUserError into an HTTPResponse.

I'm a bit unsure if BatchOperationAlreadyCompletedError is the right thing to use. It seems a bit confusing if I am at the delete billing project form, then press submit, then I lose my WiFi, then refresh the page (clicking OK when it says "do you want to resubmit this form"), then I get "this billing project already is deleted". I guess that tells me that the first request actually did make it through, but as a user, all that matters is that the BP doesn't exist anymore, right? If I mistype the name I'd get a 404, so I can't accidentally think I deleted a different BP.

Regardless, I think we should have _handle_api_error which lacks the first except and _handle_idempotence_and_api_error which calls _handle_api_error wrapped in a try-except.

@danking
Copy link
Contributor

danking commented Jul 12, 2023

Approved, but see my comment about _handle_api_error.

@danking
Copy link
Contributor

danking commented Jul 12, 2023

test_combiner_run is still way too slow.

@jigold
Copy link
Contributor Author

jigold commented Jul 12, 2023

Thank you! I agree these functions need to be rewritten.

@danking danking merged commit de11fba into hail-is:main Jul 12, 2023
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants