-
Notifications
You must be signed in to change notification settings - Fork 25
Add GeoDjango support #308
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
Draft
timgraham
wants to merge
4
commits into
mongodb:main
Choose a base branch
from
timgraham:gis
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
name: Python Tests on Atlas | ||
|
||
on: | ||
pull_request: | ||
paths: | ||
- '**.py' | ||
- '!setup.py' | ||
- '.github/workflows/test-python-atlas.yml' | ||
workflow_dispatch: | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
defaults: | ||
run: | ||
shell: bash -eux {0} | ||
|
||
jobs: | ||
build: | ||
name: Django Test Suite | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout django-mongodb-backend | ||
uses: actions/checkout@v4 | ||
with: | ||
persist-credentials: false | ||
- name: install django-mongodb-backend | ||
run: | | ||
pip3 install --upgrade pip | ||
pip3 install -e . | ||
- name: Checkout Django | ||
uses: actions/checkout@v4 | ||
with: | ||
repository: 'mongodb-forks/django' | ||
ref: 'mongogis' | ||
path: 'django_repo' | ||
persist-credentials: false | ||
- name: Install system packages for Django's Python test dependencies | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install gdal-bin libmemcached-dev | ||
- name: Install Django and its Python test dependencies | ||
run: | | ||
cd django_repo/tests/ | ||
pip3 install -e .. | ||
pip3 install -r requirements/py3.txt | ||
- name: Copy the test settings file | ||
run: cp .github/workflows/mongodb_settings.py django_repo/tests/ | ||
- name: Copy the test runner file | ||
run: cp .github/workflows/runtests.py django_repo/tests/runtests_.py | ||
- name: Start local Atlas | ||
working-directory: . | ||
run: bash .github/workflows/start_local_atlas.sh mongodb/mongodb-atlas-local:7 | ||
- name: Run tests | ||
run: python3 django_repo/tests/runtests.py --settings mongodb_settings -v 2 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
name: Python Tests with GeoDjango | ||
|
||
on: | ||
pull_request: | ||
paths: | ||
- '**.py' | ||
- '!setup.py' | ||
- '.github/workflows/test-python.yml' | ||
workflow_dispatch: | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
defaults: | ||
run: | ||
shell: bash -eux {0} | ||
|
||
jobs: | ||
build: | ||
name: Django Test Suite | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout django-mongodb-backend | ||
uses: actions/checkout@v4 | ||
with: | ||
persist-credentials: false | ||
- name: install django-mongodb-backend | ||
run: | | ||
pip3 install --upgrade pip | ||
pip3 install -e . | ||
- name: Checkout Django | ||
uses: actions/checkout@v4 | ||
with: | ||
repository: 'mongodb-forks/django' | ||
ref: 'mongogis' | ||
path: 'django_repo' | ||
persist-credentials: false | ||
- name: Install system packages for Django's Python test dependencies | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install gdal-bin libmemcached-dev | ||
- name: Install Django and its Python test dependencies | ||
run: | | ||
cd django_repo/tests/ | ||
pip3 install -e .. | ||
pip3 install -r requirements/py3.txt | ||
- name: Copy the test settings file | ||
run: cp .github/workflows/mongodb_settings.py django_repo/tests/ | ||
- name: Copy the test runner file | ||
run: cp .github/workflows/runtests.py django_repo/tests/runtests_.py | ||
- name: Start MongoDB | ||
uses: supercharge/mongodb-github-action@90004df786821b6308fb02299e5835d0dae05d0d # 1.12.0 | ||
with: | ||
mongodb-version: 6.0 | ||
- name: Run tests | ||
run: python3 django_repo/tests/runtests_.py | ||
Comment on lines
+21
to
+57
Check warningCode scanning / CodeQL Workflow does not contain permissions Medium test
Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from django.core.exceptions import ImproperlyConfigured | ||
|
||
try: | ||
from .lookups import register_lookups | ||
except ImproperlyConfigured: | ||
# GIS libraries not installed | ||
pass | ||
else: | ||
register_lookups() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import collections | ||
|
||
|
||
class Adapter(collections.UserDict): | ||
def __init__(self, obj, geography=False): | ||
""" | ||
Initialize on the spatial object. | ||
""" | ||
if obj.__class__.__name__ == "GeometryCollection": | ||
self.data = { | ||
"type": obj.__class__.__name__, | ||
"geometries": [self.get_data(x) for x in obj], | ||
} | ||
else: | ||
self.data = self.get_data(obj) | ||
|
||
def get_data(self, obj): | ||
return { | ||
"type": obj.__class__.__name__, | ||
"coordinates": obj.coords, | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
from django.contrib.gis.db.backends.base.features import BaseSpatialFeatures | ||
from django.utils.functional import cached_property | ||
|
||
|
||
class GISFeatures(BaseSpatialFeatures): | ||
has_spatialrefsys_table = False | ||
supports_transform = False | ||
|
||
@cached_property | ||
def django_test_expected_failures(self): | ||
expected_failures = super().django_test_expected_failures | ||
expected_failures.update( | ||
{ | ||
# SRIDs aren't populated: AssertionError: 4326 != None | ||
# self.assertEqual(4326, nullcity.point.srid) | ||
"gis_tests.geoapp.tests.GeoModelTest.test_proxy", | ||
# MongoDB does not support the within lookup | ||
"gis_tests.relatedapp.tests.RelatedGeoModelTest.test06_f_expressions", | ||
"gis_tests.geoapp.tests.GeoModelTest.test_gis_query_as_string", | ||
# 'Adapter' object has no attribute 'srid' | ||
"gis_tests.geoapp.test_expressions.GeoExpressionsTests.test_geometry_value_annotation", | ||
# Object of type ObjectId is not JSON serializable | ||
"gis_tests.geoapp.test_serializers.GeoJSONSerializerTests.test_fields_option", | ||
"gis_tests.geoapp.test_serializers.GeoJSONSerializerTests.test_geometry_field_option", | ||
"gis_tests.geoapp.test_serializers.GeoJSONSerializerTests.test_serialization_base", | ||
"gis_tests.geoapp.test_serializers.GeoJSONSerializerTests.test_srid_option", | ||
# No lookups are supported (yet?) | ||
"gis_tests.geoapp.tests.GeoLookupTest.test_gis_lookups_with_complex_expressions", | ||
} | ||
) | ||
return expected_failures | ||
|
||
@cached_property | ||
def django_test_skips(self): | ||
skips = super().django_test_skips | ||
skips.update( | ||
{ | ||
"inspectdb not supported.": { | ||
"gis_tests.inspectapp.tests.InspectDbTests", | ||
}, | ||
"Raw SQL not supported": { | ||
"gis_tests.geoapp.tests.GeoModelTest.test_raw_sql_query", | ||
}, | ||
"MongoDB doesn't support the SRID(s) used in this test.": { | ||
# Error messages: | ||
# - Can't extract geo keys | ||
# - Longitude/latitude is out of bounds | ||
"gis_tests.geoapp.test_expressions.GeoExpressionsTests.test_update_from_other_field", | ||
"gis_tests.layermap.tests.LayerMapTest.test_encoded_name", | ||
# SouthTexasCity fixture objects use SRID 2278 which is ignored | ||
# by the patched version of loaddata in the Django fork. | ||
"gis_tests.distapp.tests.DistanceTest.test_init", | ||
}, | ||
"ImproperlyConfigured isn't raised when using RasterField": { | ||
# Normally RasterField.db_type() raises an error, but MongoDB | ||
# migrations don't need to call it, so the check doesn't happen. | ||
"gis_tests.gis_migrations.test_operations.NoRasterSupportTests", | ||
}, | ||
"MongoDB doesn't support redundant spatial indexes.": { | ||
# Error: Index already exists with a different name | ||
"gis_tests.geoapp.test_indexes.SchemaIndexesTests.test_index_name", | ||
}, | ||
}, | ||
) | ||
return skips |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from django.contrib.gis.db.models.lookups import GISLookup | ||
from django.db import NotSupportedError | ||
|
||
|
||
def gis_lookup(self, compiler, connection): # noqa: ARG001 | ||
raise NotSupportedError(f"MongoDB does not support the {self.lookup_name} lookup.") | ||
|
||
|
||
def register_lookups(): | ||
GISLookup.as_mql = gis_lookup |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check warning
Code scanning / CodeQL
Workflow does not contain permissions Medium test