fecgov / openFEC

The first RESTful API for the Federal Election Commission. We're aiming to make campaign finance more accessible for journalists, academics, developers, and other transparency seekers.
https://api.open.fec.gov/developers
Other
483 stars 106 forks source link

Fix bug in CandidateList and CommitteeList when passing q and sort by receipts #6050

Closed fec-jli closed 1 week ago

fec-jli commented 1 week ago

Summary (required)

This PR will fix sql error in slack #bots-db-alerts-aurora

Screenshot 2024-11-07 at 3 46 33 PM Screenshot 2024-11-07 at 2 23 27 PM

sql query: https://fecgov.slack.com/archives/C3W9XBBJL/p1730837872044529

Required reviewers

1-2 developer

Impacted areas of the application

/candidates/ and candidate/search /committees/ and committee/search

How to test

1) checkout branch, run 'pytest' 2) test urls test CandidateList urls: without 'q' should get 422 http://127.0.0.1:5000/v1/candidates/?sort=receipts http://127.0.0.1:5000/v1/candidates/?&sort=-receipts

tet CandidateList urls: should return some results http://127.0.0.1:5000/v1/candidates/?q=joh&sort=receipts http://127.0.0.1:5000/v1/candidates/?q=joh&sort=-receipts http://127.0.0.1:5000/v1/candidates/?q=joh&sort=name

test CommitteeList urls: without 'q' should get 422 http://127.0.0.1:5000/v1/committees/?sort=receipts http://127.0.0.1:5000/v1/committees/?sort=-receipts

tet CommitteeList urls: should return some results http://127.0.0.1:5000/v1/committees/?sort=receipts&q=joh http://127.0.0.1:5000/v1/committees/?sort=-receipts&q=joh http://127.0.0.1:5000/v1/committees/?sort=name

After release to Prod: 1)Error urls (without passing q): https://api.open.fec.gov/v1/candidates/?sort=receipts&api_key=DEMO_KEY "message": "Cannot sort on receipts when parameter 'q' is not set”,

https://api.open.fec.gov/v1/committees/?sort=receipts&api_key=DEMO_KEY

2)Correct urls (pass q and sort): https://api.open.fec.gov/v1/candidates/?q=joh&sort=receipts&api_key=DEMO_KEY

https://api.open.fec.gov/v1/committees/?sort=receipts&q=joh&api_key=DEMO_KEY