strawberry-django
strawberry-django copied to clipboard
Feature: Add geometry filters
Description
Added GeometryLookupFilter type so that spatial filters available in GeoDjango can be used in strawberry_django.
Types of Changes
- [O] New feature
Issues Fixed or Closed by This PR
- https://github.com/strawberry-graphql/strawberry-django/issues/708
Checklist
- [V] My code follows the code style of this project.
- [V] My change requires a change to the documentation.
- [V] I have updated the documentation accordingly.
- [V] I have read the CONTRIBUTING document.
- [ ] I have added tests to cover my changes.
- [V] I have tested the changes and verified that they work and don't break anything (as well as I can manage).
Summary by Sourcery
Adds support for spatial filters from GeoDjango within strawberry-django. It introduces a new GeometryFilterLookup type and integrates it into the existing filter system, allowing users to filter data based on geographical relationships.
New Features:
- Adds GeometryLookupFilter type to enable the use of spatial filters from GeoDjango within strawberry-django, allowing filtering based on geographical relationships.
Enhancements:
- Adds support for Geometry types to the filter lookup, allowing filtering of fields based on their spatial properties.
Reviewer's Guide by Sourcery
This pull request introduces the GeometryFilterLookup input type, enabling spatial filtering capabilities in strawberry-django by leveraging GeoDjango's spatial lookups. The implementation conditionally includes this functionality only when GeoDjango is available, ensuring compatibility for users without GDAL installed.
Class diagram for GeometryFilterLookup
classDiagram
class GeometryFilterLookup {
bbcontains: Geometry
bboverlaps: Geometry
contained: Geometry
contains: Geometry
contains_properly: Geometry
coveredby: Geometry
covers: Geometry
crosses: Geometry
disjoint: Geometry
equals: Geometry
exacts: Geometry
intersects: Geometry
isempty: bool
isvalid: bool
overlaps: Geometry
touches: Geometry
within: Geometry
left: Geometry
right: Geometry
overlaps_left: Geometry
overlaps_right: Geometry
overlaps_above: Geometry
overlaps_below: Geometry
strictly_above: Geometry
strictly_below: Geometry
}
note for GeometryFilterLookup "This class is only available when GeoDjango is installed"
File-Level Changes
| Change | Details | Files |
|---|---|---|
Adds a GeometryFilterLookup input type for filtering based on GeoDjango's spatial lookups. |
|
strawberry_django/fields/filter_types.pystrawberry_django/__init__.pystrawberry_django/fields/types.py |
Possibly linked issues
- #708: The PR implements the requested geospatial filters by adding GeometryLookupFilter.
Tips and commands
Interacting with Sourcery
- Trigger a new review: Comment
@sourcery-ai reviewon 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 issueto create an issue from it. - Generate a pull request title: Write
@sourcery-aianywhere in the pull request title to generate a title at any time. You can also comment@sourcery-ai titleon the pull request to (re-)generate the title at any time. - Generate a pull request summary: Write
@sourcery-ai summaryanywhere in the pull request body to generate a PR summary at any time exactly where you want it. You can also comment@sourcery-ai summaryon the pull request to (re-)generate the summary at any time. - Generate reviewer's guide: Comment
@sourcery-ai guideon the pull request to (re-)generate the reviewer's guide at any time. - Resolve all Sourcery comments: Comment
@sourcery-ai resolveon 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 dismisson 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 reviewto trigger a new review! - Generate a plan of action for an issue: Comment
@sourcery-ai planon 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
- Contact our support team for questions or feedback.
- Visit our documentation for detailed guides and information.
- Keep in touch with the Sourcery team by following us on X/Twitter, LinkedIn or GitHub.
Codecov Report
Attention: Patch coverage is 91.89189% with 3 lines in your changes missing coverage. Please review.
Project coverage is 88.32%. Comparing base (
8898175) to head (2b1db9c).
| Files with missing lines | Patch % | Lines |
|---|---|---|
| strawberry_django/fields/filter_types.py | 93.93% | 2 Missing :warning: |
| strawberry_django/fields/types.py | 75.00% | 1 Missing :warning: |
Additional details and impacted files
@@ Coverage Diff @@
## main #710 +/- ##
==========================================
+ Coverage 88.29% 88.32% +0.03%
==========================================
Files 42 42
Lines 3920 3956 +36
==========================================
+ Hits 3461 3494 +33
- Misses 459 462 +3
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
I didn't even think about this possibility - great work @shmoon-kr
Hi. I found the following error when I was trying to run a test code. poetry run pytest
It seems something wrong when you release the most recent version. Please check.
File "/Users/evan/PycharmProjects/strawberry-django/tests/polymorphism_inheritancemanager/models.py", line 2, in
And one more question: I tried to write a test code which is run only if GeoDjango is available. But in a testing environment, GeoDjango seems not available so I cannot test geometry operations. Any suggestions?
Hi. I found the following error when I was trying to run a test code.
poetry run pytestIt seems something wrong when you release the most recent version. Please check.File "/Users/evan/PycharmProjects/strawberry-django/tests/polymorphism_inheritancemanager/models.py", line 2, in from model_utils.managers import InheritanceManager ModuleNotFoundError: No module named 'model_utils'
That's a new dev dependency that got merged from a PR yesterday. Running poetry install should fix it for you =P
And one more question: I tried to write a test code which is run only if GeoDjango is available. But in a testing environment, GeoDjango seems not available so I cannot test geometry operations. Any suggestions?
You just need to make sure that the geospatial libraries are available in your system. This should help: https://docs.djangoproject.com/en/5.1/ref/contrib/gis/install/geolibs/
From your reply, I can see that you are on MacOS, which is slightly more complicated than linux (e.g. on debian/ubuntu you just need to sudo apt-get install binutils libproj-dev gdal-bin)
@bellini666 I revised the PR as you instructed. I have one more question. Can I test whether GeoDjango is available or not with the following code from now? Then the code may get simpler.
if strawberry_django.GeometryFilterLookup is not None:
# GeoDjango is available here
@bellini666 I revised the PR as you instructed. I have one more question. Can I test whether GeoDjango is available or not with the following code from now? Then the code may get simpler.
if strawberry_django.GeometryFilterLookup is not None: # GeoDjango is available here
yep, I think it is completely fine :)