Skip to content

Conversation

@bolinocroustibat
Copy link
Contributor

@bolinocroustibat bolinocroustibat commented Sep 2, 2025

  1. We have some consistency issues with types and (non-blocking) type errors in the code. To make the code more consistent and avoid type warnings, we suggest the following rules:

    • In the business logic, checks should be handled as dict rather than Record whenever possible, since working with native Python objects greatly simplifies the manipulation logic.

    • Since asyncpg returns Record objects when querying the DB, CRUD methods should return Record types whenever possible so they remain “pure” CRUD.

This PR updates the code to follow these rules, and introduces a dict option to Check CRUD methods avoid repeating the pattern record = await Check.get() followed by check = dict(record) multiple times, in line with the DRY principle.

We also add # type: ignore when calling Check class methods using as_dict, as the IDE may not infer the type correctly for methods that can return multiple types.

  1. Reduce DB queries when cleaning up statuses in Resource.clean_up_statuses() by using a single DB request instead of a loop.

@bolinocroustibat bolinocroustibat changed the title fix: fix type issues fix: fix CRUD types returns and reduce DB queries when cleanup statuses Sep 2, 2025
@bolinocroustibat bolinocroustibat self-assigned this Sep 2, 2025
@bolinocroustibat bolinocroustibat requested review from Pierlou and maudetes and removed request for Pierlou September 2, 2025 12:55
@bolinocroustibat bolinocroustibat added code quality Indique qu'il s'agit d'une amélioration de la qualité du code (au sens très large) enhancement New feature or request labels Sep 9, 2025
@bolinocroustibat bolinocroustibat force-pushed the fix-type-issues branch 2 times, most recently from 9ebd9a8 to 2d5d343 Compare September 11, 2025 09:23
Copy link
Contributor

@maudetes maudetes left a comment

Choose a reason for hiding this comment

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

I did not look a the code in details, but it seems to me that we're adding some complexity here when the for a less structured type?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code quality Indique qu'il s'agit d'une amélioration de la qualité du code (au sens très large) enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants