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

Add checker for relationship backref usage #36

Merged
merged 4 commits into from
Jun 15, 2024
Merged

Conversation

miketheman
Copy link
Owner

@miketheman miketheman commented Jun 15, 2024

Related to #25

This pull request introduces a new checker to the flake8-sqlalchemy plugin that detects the use of backref in SQLAlchemy relationship() calls and recommends using back_populates instead. This change aims to encourage best practices in SQLAlchemy relationship definitions.

  • Implements a new checker: Adds RelationshipBackrefChecker in flake8_sqlalchemy/checkers/relationship_backref_checker.py to scan for relationship() calls that use backref and suggest back_populates.
  • Updates plugin architecture: Modifies flake8_sqlalchemy/checkers/__init__.py and flake8_sqlalchemy/plugin.py to include the new RelationshipBackrefChecker in the list of checkers and in the visitor's checker dictionary, respectively.
  • Adds tests: Introduces tests in tests/checkers/test_relationship_backref_checker.py to verify that the checker accurately identifies relationship() calls with backref and does not raise false positives for those using back_populates.

For more details, open the Copilot Workspace session.

@miketheman miketheman added the enhancement New feature or request label Jun 15, 2024
@miketheman
Copy link
Owner Author

Refactors line lengths in flake8_sqlalchemy/checkers/relationship_backref_checker.py to comply with the 88 character limit.

  • Breaks long lines in docstrings for the run and is_relationship_with_backref methods to ensure compliance with the project's line length restriction.
  • Maintains readability and code structure while adhering to the .flake8 configuration.

For more details, open the Copilot Workspace session.

Refactors line lengths in `flake8_sqlalchemy/checkers/relationship_backref_checker.py` to comply with the 88 character limit.

- Breaks long lines in docstrings for the `run` and `is_relationship_with_backref` methods to ensure compliance with the project's line length restriction.
- Maintains readability and code structure while adhering to the `.flake8` configuration.


---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/miketheman/flake8-sqlalchemy/pull/36?shareId=6c56ba85-5a9f-4269-b767-acc03d66e380).
@miketheman
Copy link
Owner Author

Adds documentation for the SQA300 check in the README.md file.

  • Introduces a new section for SQA300 to guide users on using back_populates instead of backref in SQLAlchemy relationships.
  • Provides examples of incorrect usage with backref and correct usage with back_populates, following the existing documentation structure for other checks.

For more details, open the Copilot Workspace session.

Adds documentation for the `SQA300` check in the README.md file.

- Introduces a new section for `SQA300` to guide users on using `back_populates` instead of `backref` in SQLAlchemy relationships.
- Provides examples of incorrect usage with `backref` and correct usage with `back_populates`, following the existing documentation structure for other checks.


---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/miketheman/flake8-sqlalchemy/pull/36?shareId=a6468ad9-2d08-40d2-9bc2-8ee40950ccfd).
@miketheman miketheman merged commit 1dda900 into main Jun 15, 2024
6 checks passed
@miketheman miketheman deleted the backref-checker branch June 15, 2024 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant