fix: fix CRUD types returns and reduce DB queries when cleanup statuses #331
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
dictrather thanRecordwhenever possible, since working with native Python objects greatly simplifies the manipulation logic.• Since
asyncpgreturnsRecordobjects when querying the DB, CRUD methods should returnRecordtypes whenever possible so they remain “pure” CRUD.This PR updates the code to follow these rules, and introduces a
dictoption toCheckCRUD methods avoid repeating the patternrecord = await Check.get()followed bycheck = dict(record)multiple times, in line with the DRY principle.We also add
# type: ignorewhen callingCheckclass methods usingas_dict, as the IDE may not infer the type correctly for methods that can return multiple types.Resource.clean_up_statuses()by using a single DB request instead of a loop.