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

refactor: Use dataclasses for all SQLAlchemy database classes #1328

Merged
merged 1 commit into from
Feb 14, 2024

Conversation

MoritzWeber0
Copy link
Member

@MoritzWeber0 MoritzWeber0 commented Feb 7, 2024

With dataclasses, a __init__ function is created for all database classes. This adds autocomplete and code recommendations and type checkers like mypy can check the passed types.

Since the __hash__ method was removed during this change, the intersection
method to get common projects doesn't work anymore. I changed it to a proper
database join, which is faster.

In addition, many type annotations were added. Some mypy and pylint errors
and warnings were fixed in the tests.

Resolves #1326

@MoritzWeber0 MoritzWeber0 marked this pull request as draft February 7, 2024 11:43
@MoritzWeber0 MoritzWeber0 force-pushed the sqlalchemy-dataclass branch 4 times, most recently from c4065cf to 8d48fbf Compare February 9, 2024 15:40
@MoritzWeber0 MoritzWeber0 marked this pull request as ready for review February 9, 2024 15:41
Copy link

codecov bot commented Feb 9, 2024

Codecov Report

Attention: 13 lines in your changes are missing coverage. Please review.

Comparison is base (40e7984) 73.22% compared to head (0e4bb45) 73.12%.

Files Patch % Lines
...ackend/capellacollab/projects/toolmodels/routes.py 0.00% 0 Missing and 4 partials ⚠️
...ab/projects/toolmodels/restrictions/injectables.py 0.00% 3 Missing ⚠️
backend/capellacollab/tools/routes.py 0.00% 2 Missing ⚠️
backend/capellacollab/users/routes.py 50.00% 1 Missing and 1 partial ⚠️
...acollab/projects/toolmodels/restrictions/routes.py 0.00% 1 Missing ⚠️
backend/capellacollab/tools/integrations/routes.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1328      +/-   ##
==========================================
- Coverage   73.22%   73.12%   -0.11%     
==========================================
  Files         166      166              
  Lines        5431     5448      +17     
  Branches      608      610       +2     
==========================================
+ Hits         3977     3984       +7     
- Misses       1323     1331       +8     
- Partials      131      133       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

With dataclasses, a `__init__` function is created for all database
classes. This adds autocomplete and code recommendations and type
checkers like mypy can check the passed types.

Since the `__hash__` method was removed during this change, the intersection
method to get common projects doesn't work anymore. I changed it to a proper
database join, which is faster.

In addition, many type annotations were added. Some mypy and pylint errors
and warnings were fixed in the tests.
Copy link

Quality Gate Passed Quality Gate passed

Issues
0 New issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

Copy link
Contributor

@romeonicholas romeonicholas left a comment

Choose a reason for hiding this comment

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

Latest update fixed the loading issues I saw on the projects overview and user profile pages 👍

backend/capellacollab/projects/crud.py Show resolved Hide resolved
@MoritzWeber0 MoritzWeber0 merged commit f1b15df into main Feb 14, 2024
26 checks passed
@MoritzWeber0 MoritzWeber0 deleted the sqlalchemy-dataclass branch February 14, 2024 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Integrate SQLAlchemy with dataclasses
2 participants