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

Update test scope to include django 5.1, update pre-commit hooks #683

Merged
merged 9 commits into from
Jan 3, 2025

Conversation

kwongtn
Copy link
Contributor

@kwongtn kwongtn commented Dec 30, 2024

Description

Update test scope & pre-commit hooks.
Replaced django-mptt with django-tree-queries

Types of Changes

  • Core
  • Bugfix
  • New feature
  • Enhancement/optimization
  • Documentation

Issues Fixed or Closed by This PR

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • I have tested the changes and verified that they work and don't break anything (as well as I can manage).

Summary by Sourcery

Extend support to Django 5.1 and update pre-commit hooks.

Enhancements:

  • Updated Django to 5.1.
  • Updated pre-commit hooks.

Tests:

  • Updated tests to account for Django 5.1 changes.

Signed-off-by: Kwong Tung Nan <[email protected]>
Signed-off-by: Kwong Tung Nan <[email protected]>
Signed-off-by: Kwong Tung Nan <[email protected]>
Copy link
Contributor

sourcery-ai bot commented Dec 30, 2024

Reviewer's Guide by Sourcery

This pull request updates the test scope to include Django 5.1 and adjusts the code to accommodate changes in Django 5.1, specifically the removal of support for 'index_together' in meta classes. It also updates the pre-commit hooks and modifies the test configurations to ensure compatibility with the new Django version.

No diagrams generated as the changes look simple and do not need a visual representation.

File-Level Changes

Change Details Files
Adaptation to Django 5.1 changes in model meta options.
  • Imported necessary modules for Django 5.1 compatibility.
  • Defined a custom MPTTModelBase class to handle tree model registration.
  • Added logic to manage unique_together and index_together attributes for tree models.
  • Ensured tree manager is added to models if not present.
tests/relay/mptt/models.py
Update test configurations to include Django 5.1.
  • Added Django 5.1 to the list of versions in the test matrix.
  • Updated Python version compatibility for Django 4.2, 5.0, and 5.1.
  • Included and excluded specific Python versions for different Django versions.
.github/workflows/tests.yml
Update pre-commit hook version for ruff.
  • Updated ruff-pre-commit hook from version v0.8.3 to v0.8.4.
.pre-commit-config.yaml
Exclude specific test file from pyright type checking.
  • Added 'tests/relay/mptt/models.py' to the exclude list in pyproject.toml.
pyproject.toml

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.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a 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. You can also use
    this command to specify where the summary should be inserted.

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
Contributor

@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 @kwongtn - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider keeping pyright type checking enabled for tests/relay/mptt/models.py if possible, as it could help catch potential issues earlier. If there are specific reasons for excluding it, perhaps add a comment explaining why.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟡 Testing: 1 issue found
  • 🟢 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.

pyproject.toml Outdated
@@ -177,7 +177,7 @@ max-nested-blocks = 7
[tool.pyright]
pythonVersion = "3.9"
useLibraryCodeForTypes = true
exclude = [".venv", "**/migrations", "dist", "docs"]
exclude = [".venv", "**/migrations", "dist", "docs", "tests/relay/mptt/models.py"]
Copy link
Contributor

Choose a reason for hiding this comment

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

question (testing): Could you explain why this specific test file needs to be excluded from type checking?

Excluding test files from type checking might hide potential issues. If there's a specific reason for this exclusion, it would be helpful to document it.

Copy link
Member

Choose a reason for hiding this comment

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

Do we need to exclude the whole file for this? Can we just # type: ignore or cast in the lines that need that?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, using # type: ignore or cast on the specific lines causing type errors would be a better approach than excluding the entire file. This way, we maintain type checking for the rest of the test file and only bypass it where absolutely necessary. Could you please update the PR with these more granular type ignores/casts? This will help us catch any potential type errors in the other parts of the test file. Thanks!

@codecov-commenter
Copy link

codecov-commenter commented Dec 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.17%. Comparing base (48b54fd) to head (392676c).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #683   +/-   ##
=======================================
  Coverage   89.17%   89.17%           
=======================================
  Files          41       41           
  Lines        3778     3778           
=======================================
  Hits         3369     3369           
  Misses        409      409           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@bellini666 bellini666 left a comment

Choose a reason for hiding this comment

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

Ty for this! :)

Left a couple of suggestions/questions

.github/workflows/tests.yml Outdated Show resolved Hide resolved
.github/workflows/tests.yml Outdated Show resolved Hide resolved
Comment on lines +58 to +69
include:
# Django 4.2 only supports python 3.8-3.12
- django-version: 4.2.*
python-version: '3.8'
mode: std
- django-version: 4.2.*
python-version: '3.8'
mode: geos
exclude:
# Django 5.0 only supports python 3.10+
# Django 4.2 only supports python 3.8-3.12
- django-version: 4.2.*
python-version: '3.13'
Copy link
Member

Choose a reason for hiding this comment

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

question: How does this works when we have both include and exclude?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As far as I know, they are not mutually exclusive. And according to docs

All include combinations are processed after exclude. This allows you to use include to add back combinations that were previously excluded.


Exclude works by excluding anything that matches the declared params.
For example as of the above, it excludes Django 4.2 and Python 3.13, no matter if it is geo or standard.

As for include, I added it in as it'll be redundant to add Python 3.8 to the matrix, then exclude all except Django 4.2 😅

pyproject.toml Outdated
@@ -177,7 +177,7 @@ max-nested-blocks = 7
[tool.pyright]
pythonVersion = "3.9"
useLibraryCodeForTypes = true
exclude = [".venv", "**/migrations", "dist", "docs"]
exclude = [".venv", "**/migrations", "dist", "docs", "tests/relay/mptt/models.py"]
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to exclude the whole file for this? Can we just # type: ignore or cast in the lines that need that?


if django.VERSION >= (5, 1):
Copy link
Member

Choose a reason for hiding this comment

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

question: why is this needed?

Can you add a comment with the explanation, and also pointing out where this code came from?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Turns out its not needed anymore 🥳
According to django mptt repo, django-mptt is now unmaintained. It recommends using django-tree-queries instead.

Hence I tried using it, and guess what all tests pass 😁
Will be deprecating django-mptt and removing references in an upcoming PR

Copy link
Member

@bellini666 bellini666 left a comment

Choose a reason for hiding this comment

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

Ty! :)

@bellini666 bellini666 merged commit 1ca8aaa into strawberry-graphql:main Jan 3, 2025
27 of 28 checks passed
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.

3 participants