Skip to content

Conversation

@Zwork101
Copy link

@Zwork101 Zwork101 commented Apr 19, 2025

I was working on a Quart project when I noticed quart-sqlalchemy lacked compatibility with Quart 0.20.0. I suspect the reason for that is to maintain backwards compatibility with Python 3.8. However, this can be accomplished by modifying the pyproject.toml to install the correct quart package based on python version.

Also, the tests were failing on windows, the culprit being

os.register_at_fork(before=close_connections_for_forking)

Which isn't implemented on Windows, since os.fork doesn't work in Windows. Even if it didn't raise an error, it wouldn't do anything. I am a bit concerned that this simple fix is leaving the underlying issue unaddressed, however all tests pass now. For that reason I feel good about submitting this PR, at very least to start the conversation.

Summary by Sourcery

Improve Windows compatibility and Quart version support for quart-sqlalchemy

New Features:

  • Support for Quart 0.20.0 and Python versions 3.9+

Bug Fixes:

  • Resolve Windows compatibility issue with os.register_at_fork by conditionally applying it only on POSIX systems

Enhancements:

  • Add version-specific Quart dependency based on Python version to support forward compatibility

Chores:

  • Bump package version to 3.0.5

@sourcery-ai
Copy link

sourcery-ai bot commented Apr 19, 2025

Reviewer's Guide by Sourcery

This pull request addresses compatibility issues with newer Quart versions and fixes test failures on Windows. It modifies the project dependencies to support different Quart versions based on the Python version and conditionally registers a function to close connections before forking on POSIX systems.

Updated class diagram for pyproject.toml dependencies

classDiagram
    class pyproject.toml {
        dependencies: List[str]
    }
    note for pyproject.toml "quart dependency changed to support different versions based on Python version"
Loading

File-Level Changes

Change Details Files
Added compatibility with newer versions of Quart and maintained compatibility with older versions by modifying the dependencies based on the Python version.
  • Modified the pyproject.toml file to specify different Quart versions based on the Python version.
  • Incremented the package version to 3.0.5.
pyproject.toml
Fixed test failures on Windows by conditionally registering the close_connections_for_forking function.
  • Added a check for os.name == 'posix' before registering the close_connections_for_forking function.
src/quart_sqlalchemy/bind.py
Added allowlist_externals to the tox.ini file.
  • Added allowlist_externals to the tox.ini file to allow the use of pdm.
tox.ini

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Hello @Zwork101, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

Summary of Changes

This pull request addresses compatibility issues with the quart-sqlalchemy library. Specifically, it ensures compatibility with newer versions of Quart (>=0.20.0) while maintaining backward compatibility for Python 3.8. It also fixes a test failure on Windows by conditionally registering the close_connections_for_forking function only on POSIX systems, as os.fork is not available on Windows.

Highlights

  • Quart Compatibility: The pyproject.toml file is modified to allow installation of newer versions of Quart (>=0.20.0) for Python versions >= 3.9, while maintaining compatibility with older versions for Python < 3.9.
  • Windows Compatibility: The os.register_at_fork call is now conditionally executed only on POSIX systems to prevent errors on Windows.
  • Version Update: The version of the package is bumped from 3.0.4 to 3.0.5 in both pyproject.toml and src/quart_sqlalchemy/__init__.py.

Changelog

  • pyproject.toml
    • Updated package version from 3.0.4 to 3.0.5.
    • Modified dependencies to allow quart>=0.18.3 for python versions >= 3.9 and quart<0.20.0,>=0.18.3 for python versions < 3.9.
  • src/quart_sqlalchemy/init.py
    • Updated package version from 3.0.4 to 3.0.5.
  • src/quart_sqlalchemy/bind.py
    • Wrapped the os.register_at_fork call in a conditional statement to only execute on POSIX systems.
  • tox.ini
    • Added allowlist_externals to testenv and testenv:q183 to allow pdm to run.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


A fork in the road,
Windows we must now decode,
POSIX guides the way.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request addresses compatibility issues with Quart 0.20.0 and Windows, which is great. The changes look good overall, but I have a few suggestions to improve the code and ensure its robustness.

Summary of Findings

  • Conditional import: The use of conditional import based on python version in pyproject.toml is a good approach to maintain compatibility with older versions while leveraging newer features. However, ensure that all dependencies are correctly handled for each Python version.
  • OS check for register_at_fork: The addition of if os.name == 'posix' before os.register_at_fork is necessary for Windows compatibility. However, consider whether there might be a more robust solution to handle forking in a cross-platform manner.
  • Version update: The version update in pyproject.toml and __init__.py should be consistent and follow semantic versioning principles.

Merge Readiness

The pull request is almost ready for merging. The changes address important compatibility issues. However, I recommend addressing the comments regarding the version update and the potential for a more robust solution for handling forking. I am unable to approve the pull request, and users should have others review and approve this code before merging. Once these points are addressed, the pull request should be good to go.

[project]
name = "quart-sqlalchemy"
version = "3.0.4"
version = "3.0.5"

Choose a reason for hiding this comment

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

medium

It's good to see the version number updated. However, ensure that the versioning scheme follows semantic versioning principles. Consider if a minor or patch version bump is more appropriate based on the changes made.

version = "3.1.0"

Comment on lines +261 to +262
if os.name == 'posix':
os.register_at_fork(before=close_connections_for_forking)

Choose a reason for hiding this comment

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

medium

This check for os.name == 'posix' is good for preventing errors on Windows. However, consider if there's a more robust cross-platform solution for handling forking, or if a warning should be logged when running on Windows to indicate that forking-related connection safety measures are not active.

Suggested change
if os.name == 'posix':
os.register_at_fork(before=close_connections_for_forking)
if os.name == 'posix':
os.register_at_fork(before=close_connections_for_forking)
else:
import logging
logging.warning("os.register_at_fork is not available on Windows. Connection safety during forking is not guaranteed.")

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @Zwork101 - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider using sys.platform instead of os.name for checking the operating system in src/quart_sqlalchemy/bind.py.
  • It might be better to use packaging.version to handle version comparisons in pyproject.toml.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@sonarqubecloud
Copy link

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant