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

Candidate Search sort option 500's #6043

Open
3 tasks
cnlucas opened this issue Nov 5, 2024 · 1 comment
Open
3 tasks

Candidate Search sort option 500's #6043

cnlucas opened this issue Nov 5, 2024 · 1 comment
Milestone

Comments

@cnlucas
Copy link
Member

cnlucas commented Nov 5, 2024

What we’re after

We have been having a user hit our candidate search endpoint and try to search by receipts. This passes validation, but is not a feasible option so error's out.

The call:
https://api.open.fec.gov/v1/candidates/search/?page=1&per_page=20&sort=ways&sort_hide_null=false&sort_null_only=false&sort_nulls_last=false&api_key=DEMO_KEY

In candidates.py line 45
aliases = {'receipts': models.CandidateSearch.receipts}

Action item(s)

(These are the smaller tasks that should happen in order to complete this work)

  • Research why this bug is occurring and fix it
  • Decide to either fix the receipts sorting or remove it from the validation

Completion criteria

(What does the end state look like - as long as this task(s) is done, this work is complete)

  • Candidate search either works for receipts sorting or will 422

References/resources/technical considerations

(Is there sample code or a screenshot you can include to highlight a particular issue? Here is where you reinforce why this work is important)

@cnlucas cnlucas added this to the 26.6 milestone Nov 5, 2024
@fec-jli
Copy link
Contributor

fec-jli commented Nov 6, 2024

  1. /candidates/ endpoint throws 500 error, (when sort=receipts , without q), sample url:
    http://127.0.0.1:5000/v1/candidates/?page=1&per_page=20&sort=receipts&sort_hide_null=false&sort_null_only=false&sort_nulls_last=false

  2. /candidates/search/endpoint throws 500 error, (when sort=receipts , without q), sample url:
    http://127.0.0.1:5000/v1/candidates/search/?page=1&per_page=20&sort=receipts&sort_hide_null=false&sort_null_only=false&sort_nulls_last=false&api_key=DEMO_KEY

view class: candidates.py line 37: CandidateList(ApiResource)
model class: models.Candidate and models.CandidateSearch

https://github.com/fecgov/openFEC/blob/develop/webservices/resources/candidates.py#L72-L74

The root cause:
before running select count(*) query, we should validate argument first,

        if {'receipts', '-receipts'}.intersection(
            kwargs.get('sort', [])
        ) and 'q' not in kwargs:
            raise exceptions.ApiError(
                'Cannot sort on receipts when parameter "q" is not set',
                status_code=422,
            )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 🔜 Sprint backlog
Development

No branches or pull requests

2 participants