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 #4

Open
wants to merge 5 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 issue with social connection termination
  • 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

  • New Features
    • Updated the application to be compatible with SQLAlchemy version 2.
    • Improved packaging process in line with PEP standards.
  • Bug Fixes
    • Fixed an issue in the user authentication process.
  • Refactor
    • Updated the model structure for social authentication.
  • Chores
    • Set the minimum Python version to 3.7 for enhanced compatibility.
    • Simplified the build and publish process in the Makefile.

…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 issue with social connection termination
- 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 25 minutes and 6 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 87752c6 and e670695.

Walkthrough

This update focuses on ensuring compatibility with SQLAlchemy version 2 across various Python social-auth projects, reflecting updates in packaging standards according to PEP 517/518, and fixing specific function errors. It streamlines the build and publish process for developers and addresses necessary adaptations for SQLAlchemy's major version change.

Changes

File Path Change Summary
CHANGELOG.md, Makefile Adaptations for SQLAlchemy 2, PEP standards updates, build and publish process simplifications
social_webpy/app.py Removed unnecessary attribute assignment
social_webpy/models.py Refactored ORM models for SQLAlchemy 2 compatibility

Related issues

🐰🎉
To the tune of version two,
We hopped and adapted, through and through.
With PEP in hand, and fixes so grand,
We've updated our code, to give it a brand new stand.
So here's to the changes, big and small,
A hop forward for one, a leap for us all! 🎈
🐾

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 edcfd8d and b7f0891.
Files ignored due to path filters (1)
  • pyproject.toml is excluded by: !**/*.toml
Files selected for processing (4)
  • CHANGELOG.md (1 hunks)
  • Makefile (1 hunks)
  • social_webpy/app.py (1 hunks)
  • social_webpy/models.py (3 hunks)
Additional comments: 8
Makefile (3)
  • 2-2: The update to use python -m build for the build target aligns with modern Python packaging practices and PEP 517/518 standards. This is a positive change that simplifies the build process.
  • 5-5: Using twine upload dist/* for the publish target is a secure and recommended way to upload packages to PyPI. This change is in line with best practices for Python package distribution.
  • 1-8: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [7-10]

The clean target is comprehensive, ensuring a clean state by removing bytecode files, __pycache__ directories, and build artifacts (*.egg-info, dist, build). This is crucial for maintaining a clean environment, especially with the updated build process.

CHANGELOG.md (1)
  • 10-14: The updates to the CHANGELOG.md accurately document the significant changes made in this PR, including adapting to SQLAlchemy 2, updating packaging information, setting the minimum Python version, and fixing an error. These entries are clear, adhere to the Keep a Changelog format, and provide users with important information about the changes.
social_webpy/models.py (3)
  • 4-5: The updated imports from SQLAlchemy and the use of DeclarativeBase, Mapped, mapped_column, and relationship are in line with SQLAlchemy 2's methodologies. These changes modernize the ORM models and ensure compatibility with the latest version of SQLAlchemy.
  • 17-18: The introduction of the SocialBase class as a base class using DeclarativeBase is a good practice for defining ORM models in SQLAlchemy 2, providing a clear and consistent base for model classes.
  • 32-35: The refactoring of the UserSocialAuth class to use Mapped, mapped_column, and relationship aligns with SQLAlchemy 2's ORM improvements. This ensures that the model declarations are up-to-date and leverage the latest features and best practices of SQLAlchemy.
social_webpy/app.py (1)
  • 20-25: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [10-10]

The removal of the _user attribute assignment in the __init__ method of BaseViewClass suggests a change in how the current user's state is managed. Please ensure that this change has been thoroughly tested, especially in relation to the get_current_user method and any other functionality that relies on the current user's state.

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 b7f0891 and c1e9a37.
Files ignored due to path filters (1)
  • pyproject.toml is excluded by: !**/*.toml
Files selected for processing (3)
  • .pre-commit-config.yaml (1 hunks)
  • social_webpy/app.py (2 hunks)
  • social_webpy/models.py (3 hunks)
Files skipped from review due to trivial changes (1)
  • .pre-commit-config.yaml
Additional comments: 6
social_webpy/models.py (4)
  • 16-17: The SocialBase class is correctly defined as a placeholder for further extensions. However, ensure that SocialBase is instantiated from declarative_base() as suggested in the previous comment.
  • 32-35: The UserSocialAuth model class correctly uses mapped_column and Mapped types, aligning with SQLAlchemy 2 standards. Ensure that User.id is correctly defined in the user model and that the relationship's backref is properly set up.
  • 1-8: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [42-60]

The model classes Nonce, Association, Code, and Partial are correctly defined as placeholders, inheriting behavior from their respective mixins and SocialBase. No specific fields or methods are added, which is appropriate for their intended use.

  • 1-8: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [62-68]

The WebpyStorage class correctly aggregates the model classes for use in the storage backend, ensuring that each component of the social authentication process is properly managed.

social_webpy/app.py (2)
  • 5-5: The import statement has been updated to remove duplicates, which is a good practice for maintaining clean and readable code. Ensure that all necessary utilities are still imported for the application's functionality.
  • 20-25: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [11-29]

The BaseViewClass constructor and methods appear to be correctly structured, with appropriate session and strategy handling. However, the AI-generated summary mentioned changes related to the _user attribute that are not visible in the provided code. Ensure that any modifications to the _user attribute handling are correctly implemented and tested.

Comment on lines 4 to 5
from sqlalchemy import String, ForeignKey
from sqlalchemy.orm import relationship, DeclarativeBase, Mapped, mapped_column
Copy link

Choose a reason for hiding this comment

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

The import statements have been updated to align with SQLAlchemy 2 standards. However, it's important to ensure that DeclarativeBase is correctly imported from sqlalchemy.orm as declarative_base to maintain consistency with SQLAlchemy's expected usage patterns.

- from sqlalchemy.orm import relationship, DeclarativeBase, Mapped, mapped_column
+ from sqlalchemy.orm import relationship, declarative_base, Mapped, mapped_column
+ SocialBase = declarative_base()

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
from sqlalchemy import String, ForeignKey
from sqlalchemy.orm import relationship, DeclarativeBase, Mapped, mapped_column
from sqlalchemy import String, ForeignKey
from sqlalchemy.orm import relationship, declarative_base, Mapped, mapped_column
SocialBase = declarative_base()

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: 4

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between c1e9a37 and 87752c6.
Files selected for processing (6)
  • .travis.yml (1 hunks)
  • social_webpy/init.py (1 hunks)
  • social_webpy/app.py (3 hunks)
  • social_webpy/models.py (2 hunks)
  • social_webpy/strategy.py (4 hunks)
  • social_webpy/utils.py (2 hunks)
Files skipped from review due to trivial changes (3)
  • social_webpy/init.py
  • social_webpy/strategy.py
  • social_webpy/utils.py
Files skipped from review as they are similar to previous changes (2)
  • social_webpy/app.py
  • social_webpy/models.py

python:
- "2.7"
- '2.7'
Copy link

Choose a reason for hiding this comment

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

The Python version 2.7 is specified, but the PR objectives mention setting the minimum Python version to 3.7. This version should be updated or removed to align with the new minimum version requirement.

- - '2.7'

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
- '2.7'

- python: pypy
env:
- TEST_REQUIREMENTS=social/tests/requirements-pypy.txt
- python: '3.3'
Copy link

Choose a reason for hiding this comment

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

Python version 3.3 is specified, which is below the new minimum Python version of 3.7. This version should be updated or removed to reflect the updated requirements.

- - python: '3.3'

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
- python: '3.3'

env:
- REQUIREMENTS=requirements-python3.txt
- TEST_REQUIREMENTS=social/tests/requirements-python3.txt
- python: '3.4'
Copy link

Choose a reason for hiding this comment

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

Python version 3.4 is specified, which is also below the new minimum Python version of 3.7. This version should be updated or removed to comply with the new version requirements.

- - python: '3.4'

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
- python: '3.4'

Comment on lines +28 to +30
- python setup.py -q install
- travis_retry pip install -r $REQUIREMENTS
- travis_retry pip install -r $TEST_REQUIREMENTS
Copy link

Choose a reason for hiding this comment

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

The installation commands use python setup.py -q install, which might not align with the transition to PEP 517/518 as mentioned in the PR objectives. Consider using a more modern approach for package installation that is compatible with PEP 517/518, such as using pip to install the package directly from the source with the pyproject.toml file.

- - python setup.py -q install
+ - pip install .

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
- python setup.py -q install
- travis_retry pip install -r $REQUIREMENTS
- travis_retry pip install -r $TEST_REQUIREMENTS
- pip install .
- travis_retry pip install -r $REQUIREMENTS
- travis_retry pip install -r $TEST_REQUIREMENTS

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