open-contracting / credere-backend

A tool that facilitates the participation of Micro, Small, and Medium businesses (MSMEs) in the Colombian public procurement market.
https://credere.readthedocs.io
BSD 3-Clause "New" or "Revised" License
5 stars 0 forks source link

msme_approved_count is reinitialized in get_borrower_opt_in_stats() #331

Closed jpmckinney closed 4 weeks ago

jpmckinney commented 1 month ago

It's assigned two different times, and then used once to construct the return value.

I assume the second one is the correct one, in which case we just delete the first one (and move the code for the second one into the return dict, to prevent this type of bug).

jpmckinney commented 1 month ago

Actually, I'll just make the change in #333

Here's the first assignment:

    msme_approved_count = (
        session.query(Application.id)
        .join(Award, Award.id == Application.award_id)
        .join(Borrower, Borrower.id == Application.borrower_id)
        .filter(col(Application.lender_completed_at).isnot(None))
        .filter(Borrower.size != BorrowerSize.BIG)
        .group_by(Application.id)
        .count()
    )

And the second (retained) one is:

    msme_approved_count = (
        session.query(Application.id)
        .join(Borrower, Borrower.id == Application.borrower_id)
        .filter(col(Application.lender_completed_at).isnot(None))
        .filter(Borrower.size != BorrowerSize.BIG)
        .count()
    )