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 12 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
  • 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 model and access code for compatibility with SQLAlchemy version 2.
    • Modified SQLAlchemy ORM models for Social Auth, including base class declaration and column definitions.
  • Bug Fixes
    • Fixed an error related to csrfmiddlewaretoken argument in views.py.
  • Chores
    • Simplified build and publish commands in the development process.
    • Updated packaging information files to comply with PEP 517 and PEP 518.
    • Set Python minimum version to 3.7 for compatibility with SQLAlchemy 2.

…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
- 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

@search5 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 22 minutes and 8 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 0dac011 and 350d9a3.

Walkthrough

This update focuses on making the codebase compatible with SQLAlchemy version 2, alongside modernizing the project setup to adhere to PEP 517 and PEP 518. It also includes various code style adjustments, such as standardizing quote usage and reordering imports, and updates the build and publish process for simplicity and efficiency.

Changes

Files Change Summary
CHANGELOG.md, Makefile Updated for SQLAlchemy 2 compatibility, PEP 517/518 packaging, simplified build/publish commands, and Python 3.7 requirement.
social_cherrypy/__init__.py Updated __version__ variable quote style.
social_cherrypy/models.py, social_cherrypy/strategy.py, social_cherrypy/utils.py Refactored for SQLAlchemy 2, code style updates (quotes, imports).
.travis.yml Updated Python versions, environment variables, and package commands.
.pre-commit-config.yaml Added pre-commit hooks for code quality and formatting.

Related issues

Poem

In the code forest, amidst the bytes and trees,
A rabbit hopped, with ease in the breeze.
"To SQLAlchemy 2, we leap!" it cheered,
With every line of code, the future neared.
🐇💻🌟
"Let's celebrate," it whispered, "for our code is neat,
Together, in this digital burrow, we meet."

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 9bbede4 and b8cc12c.
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_cherrypy/models.py (3 hunks)
  • social_cherrypy/views.py (1 hunks)
Additional comments: 8
Makefile (3)
  • 2-2: The build target uses the modern python -m build command, which is a good practice as it adheres to PEP 517/518, promoting the use of build backends.
  • 5-5: The publish target correctly uses twine upload dist/* for publishing packages. This is a secure and recommended way to upload packages to PyPI, ensuring that credentials are handled safely.
  • 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 effectively removes bytecode files, __pycache__ directories, and build artifacts. This is a crucial step in maintaining a clean workspace and avoiding potential issues with stale files.

social_cherrypy/views.py (1)
  • 25-25: The addition of the csrfmiddlewaretoken parameter to the disconnect function is a positive change, enhancing security by potentially mitigating CSRF attacks. However, ensure that all calls to this function are updated to include this new parameter, and consider validating the token within the function to effectively prevent CSRF attacks.
CHANGELOG.md (1)
  • 10-14: The changelog entries accurately reflect the significant updates made in this PR, including the transition to SQLAlchemy 2, build process modernization, Python version compatibility, and the fix for the csrfmiddlewaretoken argument. It's important to ensure that these entries remain clear and concise to effectively communicate the changes to users and contributors.
social_cherrypy/models.py (3)
  • 4-5: The imports from sqlalchemy and the use of DeclarativeBase, Mapped, and mapped_column from SQLAlchemy 2 are correctly implemented. These changes align with SQLAlchemy 2's practices for declaring models and mapping columns, promoting better compatibility and code clarity.
  • 15-16: The declaration of SocialBase as a subclass of DeclarativeBase is a good practice for defining the base class for all models. This ensures a consistent base class across the application, facilitating easier maintenance and upgrades.
  • 31-34: The refactoring of the UserSocialAuth model to use Mapped and mapped_column for defining columns is in line with SQLAlchemy 2's recommendations. This approach enhances type safety and clarity in model definitions. Ensure that the relationship between UserSocialAuth and the User model is correctly configured, especially the backref to social_auth, to maintain the integrity of the relationship and ease navigation between associated records.

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 b8cc12c and a911776.
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_cherrypy/models.py (3 hunks)
Additional comments: 2
social_cherrypy/models.py (2)
  • 15-16: The introduction of the SocialBase class as a custom base class for ORM models is a good practice for SQLAlchemy 2. It allows for centralized configuration and customization of model behavior. Ensure that any necessary configurations specific to your project are included in this class.
  • 32-35: The UserSocialAuth model correctly uses SQLAlchemy 2's Mapped and mapped_column for declaring column types and relationships. This aligns with modern SQLAlchemy practices. However, ensure that the UID_LENGTH and User.id are appropriately configured and exist. It's also important to verify that the relationship with User is correctly set up, especially the backref to 'social_auth', to ensure it does not introduce any unintended behavior in the user model.

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 a911776 and d0a118c.
Files selected for processing (6)
  • .travis.yml (1 hunks)
  • social_cherrypy/init.py (1 hunks)
  • social_cherrypy/models.py (2 hunks)
  • social_cherrypy/strategy.py (4 hunks)
  • social_cherrypy/utils.py (3 hunks)
  • social_cherrypy/views.py (1 hunks)
Files skipped from review due to trivial changes (1)
  • social_cherrypy/init.py
Files skipped from review as they are similar to previous changes (1)
  • social_cherrypy/models.py
Additional comments: 11
.travis.yml (5)
  • 5-6: The environment variables REQUIREMENTS and TEST_REQUIREMENTS are correctly set. Ensure that the paths specified in these variables are accurate and the files exist in the repository.
  • 11-21: The inclusion of PyPy and Python 3.3, 3.4 versions is noted. Given the PR's focus on modernization and Python 3.7 compatibility, verify if support for these older versions is still required. Python 3.3 and 3.4 have reached end-of-life and may not be compatible with newer libraries and standards.
  • 25-26: The addition of libxmlsec1-dev and swig packages under addons is appropriate for dependencies that require native extensions. Confirm these packages are necessary for the project's dependencies.
  • 28-30: The installation commands are standard and use best practices such as travis_retry for resilience against network issues. Ensure that setup.py is still relevant given the move to PEP 517/518 standards mentioned in the PR objectives.
  • 32-32: The script command for running tests with coverage is correctly specified. Ensure that the social/tests directory exists and contains the relevant tests.
social_cherrypy/views.py (2)
  • 3-3: The reorganization of import statements improves readability and maintains a logical order. This change aligns with Python best practices.
  • 8-29: The changes in string literals from single to double quotes and the update of variable names within methods are cosmetic but contribute to consistency across the codebase. Ensure that these changes do not affect any string comparisons or dictionary key accesses that might rely on specific quote types.
social_cherrypy/strategy.py (2)
  • 40-48: > 📝 NOTE

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

The changes in dictionary key quotes from single to double quotes and the updates in method parameters and return values enhance consistency. These changes are cosmetic and should not impact functionality. However, ensure that all related code segments have been updated to maintain consistency.

  • 64-64: Modifying the is_response function to check for str type instead of six.string_types aligns with the move towards Python 3. This change is appropriate given the PR's objectives. Ensure that all response handling in the application is compatible with this change.
social_cherrypy/utils.py (2)
  • 6-10: The reordering of imports and the update of dictionary key quotes to double quotes improve code readability and consistency. These changes align with Python best practices.
  • 30-60: > 📝 NOTE

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

The modifications in string formatting to use double quotes consistently across the file contribute to a uniform coding style. Ensure that these changes do not affect any functionality, especially in cases where string interpolation or special characters are involved.

.travis.yml Outdated
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.

Python 2.7 is listed, which is no longer supported. Consider removing or updating this version to reflect the project's current Python compatibility, especially since the PR mentions ensuring compatibility with Python 3.7.

Comment on lines 24 to 25
def disconnect(self, backend, association_id=None, csrfmiddlewaretoken=None):
user = getattr(cherrypy.request, "user", None)
Copy link

Choose a reason for hiding this comment

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

The introduction of a csrfmiddlewaretoken parameter in the disconnect method potentially enhances security by preventing CSRF attacks. Ensure that this parameter is validated properly and used consistently across the application.

Consider implementing CSRF token validation if not already done to fully leverage the security benefits of this change.

import cherrypy

import six
Copy link

Choose a reason for hiding this comment

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

The import of six is noted, which is a Python 2 and 3 compatibility library. Given the PR's focus on modernization and Python 3.7 compatibility, evaluate if the dependency on six is still necessary. If the codebase no longer supports Python 2, consider removing six and updating relevant code.



def strategy(*args, **kwargs):
warnings.warn('@strategy decorator is deprecated, use @psa instead')
warnings.warn("@strategy decorator is deprecated, use @psa instead")
Copy link

Choose a reason for hiding this comment

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

The deprecation warning for the @strategy decorator and the recommendation to use @psa instead is a good practice for guiding developers towards updated methods. Ensure that all instances of @strategy in the codebase have been replaced with @psa to avoid confusion.

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 d0a118c and b79c985.
Files ignored due to path filters (1)
  • pyproject.toml is excluded by: !**/*.toml
Files selected for processing (1)
  • social_cherrypy/strategy.py (4 hunks)
Files skipped from review as they are similar to previous changes (1)
  • social_cherrypy/strategy.py

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 b79c985 and 2244c80.
Files selected for processing (1)
  • social_cherrypy/strategy.py (4 hunks)
Files skipped from review as they are similar to previous changes (1)
  • social_cherrypy/strategy.py

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 2244c80 and cb7bed5.
Files selected for processing (2)
  • social_cherrypy/strategy.py (4 hunks)
  • social_cherrypy/views.py (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • social_cherrypy/strategy.py
  • social_cherrypy/views.py

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 cb7bed5 and 0dac011.
Files selected for processing (2)
  • social_cherrypy/strategy.py (4 hunks)
  • social_cherrypy/views.py (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • social_cherrypy/strategy.py
  • social_cherrypy/views.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.

None yet

1 participant