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

Open
wants to merge 6 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
  • 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.

I'm sure there will be other PRs like this one in the future, so I'm mentioning this one in advance.

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 model and access code for compatibility with SQLAlchemy version 2.
    • Set minimum Python version to 3.7 to match SQLAlchemy 2 requirements.
  • Refactor

    • Modified several methods across mixins for improved functionality and compatibility with new version of SQLAlchemy.
  • Chores

    • Updated build and publish commands in Makefile to simplify the process.
    • Updated packaging information files according to PEP 517 and PEP 518.

…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
- 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 10 minutes and 27 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 22fdf81 and 4c75866.

Walkthrough

The modifications primarily adapt the codebase for compatibility with SQLAlchemy version 2, reflecting a significant shift in the way database interactions are handled. This includes changes to model declarations, query methods, and the build and publish process to align with modern Python packaging standards as defined by PEP 517 and PEP 518, setting a new baseline for Python version compatibility and streamlining development workflows.

Changes

File Path Change Summary
social_sqlalchemy/storage.py Adapted for SQLAlchemy 2; updated column declarations and query methods.
CHANGELOG.md Documented updates for SQLAlchemy 2 compatibility, packaging changes, and Python version requirement.
Makefile Updated build and publish commands to follow modern Python packaging practices.

Related issues

🐇 A Poem by CodeRabbit

In the world of code, where changes abound,
A rabbit hopped in, with a leap and a bound.
"To SQLAlchemy 2, we must adapt," it said,
Updating models and queries, ahead it led.
With PEPs in mind, it danced with glee,
"For a better code world, just follow me!"
🌟💻📦🐾

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 b489c10 and 22fdf81.
Files ignored due to path filters (1)
  • pyproject.toml is excluded by: !**/*.toml
Files selected for processing (3)
  • CHANGELOG.md (1 hunks)
  • Makefile (1 hunks)
  • social_sqlalchemy/storage.py (10 hunks)
Additional comments: 17
Makefile (2)
  • 2-2: The update to use python -m build aligns with modern Python packaging practices. Good change!
  • 5-5: Using twine upload dist/* for publishing packages is a best practice and ensures secure uploads. Well done!
CHANGELOG.md (1)
  • 10-13: The updates documented in the CHANGELOG.md accurately reflect the PR's objectives and changes. It's important to keep this file updated for clear communication with users. Great job!
social_sqlalchemy/storage.py (14)
  • 3-3: Adding from typing import Optional is a good practice for type hinting, enhancing code readability and maintainability.
  • 13-13: Replacing Column, Integer with select, delete, String, func, Integer aligns with SQLAlchemy 2's approach to handling database operations. This change is necessary for compatibility.
  • 18-18: Introducing from sqlalchemy.orm import declared_attr, Mapped, mapped_column is crucial for the new way SQLAlchemy 2 handles model declarations. This is a positive change for compatibility.
  • 57-57: Changing the _query method to use select(cls) instead of cls._session().query(cls) aligns with SQLAlchemy 2's new query interface. This is a necessary update for compatibility.
  • 92-100: The modifications to column declarations using Mapped and mapped_column are in line with SQLAlchemy 2's requirements for type hinting and column mapping. This enhances the code's compatibility and readability.
  • 113-126: Updating the allowed_to_disconnect method to use the new query interface and scalar for counting is a good practice for SQLAlchemy 2 compatibility. It also improves the method's readability and performance.
  • 137-152: The changes to user_exists method, including the use of select(func.count()) and scalar, align with SQLAlchemy 2's approach and improve the method's efficiency.
  • 164-164: Updating get_user to directly use _session().get simplifies the code and is a good practice for fetching records in SQLAlchemy 2.
  • 168-168: The update to get_users_by_email to use scalar for direct fetching aligns with SQLAlchemy 2's practices, improving code efficiency.
  • 161-179: > 📝 NOTE

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

The modifications in get_social_auth_for_user to use the new query interface and scalars for fetching multiple records are well-aligned with SQLAlchemy 2's paradigms.

  • 200-203: The updates to column declarations in SQLAlchemyNonceMixin using Mapped and mapped_column are necessary for SQLAlchemy 2 compatibility and enhance code readability.
  • 218-224: The changes in SQLAlchemyAssociationMixin to column declarations and the use of delete in the remove method align with SQLAlchemy 2's requirements and best practices.
  • 255-257: The modifications to column declarations in SQLAlchemyCodeMixin using Mapped and mapped_column are in line with SQLAlchemy 2's approach, enhancing compatibility and readability.
  • 266-270: The updates to column declarations in SQLAlchemyPartialMixin using Mapped and mapped_column ensure compatibility with SQLAlchemy 2 and improve the code's maintainability.

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