Skip to content

API server code health pass - rework parse* & extract* methods #1062

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

Merged
merged 1 commit into from
Jan 18, 2023

Conversation

rzats
Copy link
Contributor

@rzats rzats commented Dec 30, 2022

Partially addresses #998.

Prerequisites:

  • Unless it is a documentation hotfix it should be merged against the dev branch
  • Branch is up-to-date with the branch to be merged with, i.e. dev
  • Build is successful
  • Code is cleaned up and formatted

Summary

Fixes a set of issues in the server code as described here.

  • Moves parse_* and extract_* methods to params.py instead of validate.py.
  • Also does the same with several methods from covidcast.py.
  • Also renames the methods to more accurately represent their purpose (pending some discussion with George)

@rzats rzats requested a review from melange396 December 30, 2022 19:45
Copy link
Collaborator

@melange396 melange396 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 pretty good, but out of curiousity: Did you do a straight copy of the 11 methods moved to _params.py from _validate.py and covidcast.py, or did you make changes to them? Similarly, any changes in the test methods moved from test_validate.py to test_params.py? I presume there are no such changes, but i cant easily tell from the diffs shown by github.

...

also, optionally:

(if you dont want to do the following stuff now, its not a problem -- i will just put these comments into #998 for a future pass)

It would be nice if [for now] the only places request is used as an import is in _params.py (which is specifically used to get "parameters" from a "request"), in endpoints (which each legitimately process a "request"), in main.py (which is effectively an endpoint itself), and in _common.py (which uses it in the context of pre- and post-request app decorators)... To that end, can we:

  • make the methods left in _validate.py take request as a function argument instead of as an import?
  • change print_non_standard() and create_printer() in _printer.py to take format as an argument instead of pulling it from the imported request?

...which leaves _exceptions.py, where the constructor for EpiDataException uses request in a hacky special-cased compatibility workaround. The subclasses of the exception make use of it too. We can leave that one alone [for now].

Comment on lines 33 to 35
from .._validate import(
require_all,
require_any,
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

you can remove parens and newlines since this is now a single import

@rzats rzats force-pushed the rzatserkovnyi/code-health-parse-extract branch from adec660 to 281d206 Compare January 16, 2023 19:43
@rzats rzats force-pushed the rzatserkovnyi/code-health-parse-extract branch from 281d206 to 789fda2 Compare January 16, 2023 19:48
@rzats
Copy link
Contributor Author

rzats commented Jan 16, 2023

@melange396 fixed some merge conflicts and your comment, so the PR should be good to review again!

Regarding your followup questions:

  • The methods are moved as-is, no changes there.
  • The request changes are actually within the scope of this pass (AKA, to be done this week) and in fact mostly finished in a local branch; I'd just like to put them in a separate PR after this one is merged.

@rzats rzats requested a review from melange396 January 16, 2023 22:30
Copy link
Collaborator

@melange396 melange396 left a comment

Choose a reason for hiding this comment

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

looks good, we will just need to remember to refer to my comment above regarding request as an argument (in the subsequent PR)

@rzats rzats merged commit 4a6f0ae into dev Jan 18, 2023
@rzats rzats deleted the rzatserkovnyi/code-health-parse-extract branch January 18, 2023 15:16
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.

2 participants