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

Binding DB sessions based on SQLAlchemy 1, changing how to declare Base Model classes, and other code modernization #5

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

search5
Copy link

@search5 search5 commented Feb 24, 2024

  • DB session binding based on SQLAlchemy 2, Base Model class declaration method change
  • Reflected select, delete code based on SQLAlchemy 2
  • Changed how to declare Model class based on SQLAlchemy 2
  • Fixed import errors found in several examples
  • Added pyproject.toml file after removing setup.py due to the introduction of PEP 517/518
  • Fixed minimum installed version to Python 3.7

Proposed changes

With the introduction of PEP 517/518, the Python package build process has changed to allow the use of multiple build backends. We've improved the build process accordingly.
In addition, we improved the program to ensure that several previously developed libraries work properly with the newly updated SQLAlchemy 2 in January 2023.

Please consider this PR and look forward to the new version release. I took the time to fix the program and submit the patch because I'm planning to include it in a Korean Flask-based programming book I'm writing.

Types of changes

Please check the type of change your PR introduces:

  • Release (new release request)
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Code style update (PEP8, lint, formatting, renaming, etc)
  • Refactoring (no functional changes, no api changes)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Build related changes (build process, tests runner, etc)
  • Other (please describe):

Checklist

Put an x in the boxes that apply. You can also fill these out after creating
the PR. If you're unsure about any of them, don't hesitate to ask. We're here to
help! This is simply a reminder of what we are going to look for before merging
your code.

  • Lint and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added documentation to https://github.com/python-social-auth/social-docs
  • I created a running environment for the program and carefully verified that my modifications worked.

Summary by CodeRabbit

  • Refactor
    • Updated the model and access code for compatibility with SQLAlchemy version 2.
    • Simplified the build and publish process for the package.
  • Chores
    • Set the minimum Python version to 3.7 to align with SQLAlchemy 2 requirements.
    • Updated packaging information to comply with PEP 517 and PEP 518.
  • Chores
    • Introduced hooks for various tools in the .pre-commit-config.yaml file.
  • Chores
    • Updated the declaration of the __version__ variable in social_flask_sqlalchemy/__init__.py.
  • Refactor
    • Enhanced ORM models for Social Auth within Flask SQLAlchemy by refactoring the base class and adjusting column declarations in social_flask_sqlalchemy/models.py.

…se Model classes, and other code modernization

- DB session binding based on SQLAlchemy 2, Base Model class declaration method change
- Reflected select, delete code based on SQLAlchemy 2
- Changed how to declare Model class based on SQLAlchemy 2
- Fixed import errors found in several examples
- Added pyproject.toml file after removing setup.py due to the introduction of PEP 517/518
- Fixed minimum installed version to Python 3.7
Copy link

coderabbitai bot commented Feb 24, 2024

Warning

Rate Limit Exceeded

@pre-commit-ci[bot] has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 24 minutes and 38 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.

Commits Files that changed from the base of the PR and between 01e4ddb and f60a7e3.

Walkthrough

The updates involve making the codebase compatible with SQLAlchemy version 2, adopting new Python packaging standards as defined by PEP 517 and PEP 518, and ensuring the minimum Python version is set to 3.7. Additionally, there's a refactoring of the base class for SQLAlchemy models in the social_flask_sqlalchemy project.

Changes

File(s) Change Summary
CHANGELOG.md, Makefile Updated for SQLAlchemy 2 compatibility, PEP 517/518 packaging standards, and Python >=3.7 requirement.
social_flask_sqlalchemy/__init__.py Updated the __version__ variable declaration.
social_flask_sqlalchemy/models.py Refactored the base class for SQLAlchemy models and adjusted user_id column declaration.
.pre-commit-config.yaml Introduced hooks for various tools and custom hooks for formatting YAML files.

Related issues

🐇🎉

A hop, a skip, in the code we dip,

To SQLAlchemy 2, we make the flip.

With PEPs in tow, our packages glow,

Python 3.7, now setting the flow.

Cheers to the changes, big and small,

In the world of code, we stand tall. 🥕🌟

🎉🐇

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 09610f4 and 5f0bd45.
Files ignored due to path filters (2)
  • pyproject.toml is excluded by: !**/*.toml
  • setup.cfg is excluded by: !**/*.cfg
Files selected for processing (3)
  • CHANGELOG.md (1 hunks)
  • Makefile (1 hunks)
  • social_flask_sqlalchemy/models.py (4 hunks)
Additional comments: 5
Makefile (2)
  • 2-2: The use of python -m build is a modern and recommended approach for building packages, aligning with PEP 517/518. This command ensures that the build process is handled by a build backend specified in pyproject.toml, making the process more standardized and reliable.
  • 5-5: Using twine upload dist/* for publishing packages is a secure and recommended practice. It ensures that the package is uploaded over HTTPS, protecting the credentials and integrity of the package. This change simplifies and secures the publish process.
CHANGELOG.md (1)
  • 10-13: The changelog entries clearly document the significant changes made in this PR, including compatibility with SQLAlchemy 2, updates to packaging files per PEP 517 and PEP 518, and the restriction of the Python version to 3.7 or higher. This documentation is essential for users to understand the impact of the changes and adheres to the Keep a Changelog format.
social_flask_sqlalchemy/models.py (2)
  • 15-16: The introduction of PSABase as a base class for SQLAlchemy models, inheriting from DeclarativeBase, is a good practice for organizing model inheritance and ensuring compatibility with SQLAlchemy 2. This change aligns with the PR's objective of updating the codebase for SQLAlchemy 2 compatibility.
  • 79-80: The adjustment of the user_id column declaration in UserSocialAuth to use mapped_column with a ForeignKey constraint and setting it as non-nullable and indexed is a correct and efficient way to declare model relationships in SQLAlchemy 2. This change ensures that the UserSocialAuth model is compatible with SQLAlchemy 2's standards and practices.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 5f0bd45 and ab42bc5.
Files ignored due to path filters (1)
  • pyproject.toml is excluded by: !**/*.toml
Files selected for processing (2)
  • .pre-commit-config.yaml (1 hunks)
  • social_flask_sqlalchemy/models.py (4 hunks)
Additional comments: 7
.pre-commit-config.yaml (5)
  • 4-10: The pre-commit hook configuration for pre-commit/pre-commit-hooks is correctly set up with standard hooks like check-merge-conflict, debug-statements, and mixed-line-ending. The mixed-line-ending hook is specifically configured to fix line endings to LF (--fix=lf), which is a good practice for cross-platform consistency.
  • 11-15: The isort hook is correctly configured with the --profile=black argument, ensuring that imports are sorted in a manner that is compatible with the black code formatter. This consistency between formatters is crucial for maintaining code quality.
  • 21-24: The black formatter is correctly configured without specific arguments. This is standard practice, as black has its own opinionated formatting rules that usually don't require customization.
  • 25-28: The flake8 linter is set up without specific arguments. Ensure that the project's coding standards are fully compatible with flake8's default rules, or consider configuring it with a .flake8 configuration file for more granular control.
  • 33-37: The pretty-format-yaml hook is configured with --autofix and --indent '2', which automatically fixes YAML files to have a 2-space indentation. This is a good practice for maintaining consistency in YAML file formatting across the project.
social_flask_sqlalchemy/models.py (2)
  • 16-17: Refactoring the PSABase class to use DeclarativeBase aligns with SQLAlchemy 2's recommended practices for declaring base classes. This change ensures that the models are correctly integrated with the SQLAlchemy ORM.
  • 79-80: The use of mapped_column for the user_id column in UserSocialAuth is a significant change that aligns with SQLAlchemy 2's new paradigm. However, ensure that all references to UserSocialAuth.user_id throughout the codebase are updated to accommodate this change, if necessary.
Verification successful

The search for references to UserSocialAuth.user_id in the project only found its declaration in social_flask_sqlalchemy/models.py. This indicates that there are no other parts of the codebase that directly reference UserSocialAuth.user_id, suggesting that the change to use mapped_column does not require updates elsewhere to accommodate this change. Therefore, the concern mentioned in the review comment does not apply.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for references to UserSocialAuth.user_id in the project
rg "UserSocialAuth.user_id"

Length of output: 105

Comment on lines +16 to +20
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.1
hooks:
- id: pyupgrade
args: [--py36-plus]
Copy link

Choose a reason for hiding this comment

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

The pyupgrade hook is set to use the --py36-plus argument. Given the PR's objective to ensure compatibility with Python 3.7 and above, consider updating this argument to --py37-plus to better align with the project's Python version requirements.

-    args: [--py36-plus]
+    args: [--py37-plus]

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.1
hooks:
- id: pyupgrade
args: [--py36-plus]
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.1
hooks:
- id: pyupgrade
args: [--py37-plus]

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between ab42bc5 and 01e4ddb.
Files selected for processing (2)
  • social_flask_sqlalchemy/init.py (1 hunks)
  • social_flask_sqlalchemy/models.py (4 hunks)
Files skipped from review due to trivial changes (1)
  • social_flask_sqlalchemy/init.py
Files skipped from review as they are similar to previous changes (1)
  • social_flask_sqlalchemy/models.py

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

Successfully merging this pull request may close these issues.

1 participant