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

django-rest-framework-gis #31

Closed
jayvdb opened this issue Apr 24, 2020 · 21 comments
Closed

django-rest-framework-gis #31

jayvdb opened this issue Apr 24, 2020 · 21 comments
Labels
enhancement New feature or request fix confirmation pending issue has been fixed and confirmation from issue reporter is pending help wanted Extra attention is needed

Comments

@jayvdb
Copy link
Contributor

jayvdb commented Apr 24, 2020

https://github.com/openwisp/django-rest-framework-gis causes warning

could not resolve serializer field GeometryField(allow_null=True, required=False). defaulting to "string"

It definitely isnt a string ;-)

@tfranzel tfranzel added the enhancement New feature or request label Apr 24, 2020
@tfranzel
Copy link
Owner

i'd like to see 3rd party support for GIS. i stumbled on it before. would you mind doing a PR for it to spread the workload a bit?

before you can do it, i need to introduce another extension mechanic. We already have OpenApiSerializerExtension but this also requires OpenApiSerializerFieldExtension which i will add. this is the second time i would have needed it.

@jayvdb
Copy link
Contributor Author

jayvdb commented Apr 24, 2020

Ya, I am relying on these fields so I need it sooner than later, so I'll do the final part of getting it working and tested, after you have done any helpers you think will help.

@tfranzel
Copy link
Owner

the facilities are now available. have a look at https://github.com/tfranzel/drf-spectacular/blob/master/tests/test_extensions.py on how to use it. this should allow you to address pretty much every custom serializer field.

the extensions, as mentioned before, can be located anywhere as long as the interpreter comes by at least once. please do a PR once you are happy with the GIS extensions. would be much appreciated.

@jayvdb
Copy link
Contributor Author

jayvdb commented Apr 25, 2020

Created draft #38 . I havent played with it yet, but it gives you an idea of what else we might want to support custom complex fields.

The most obvious is that the schema is not small, and it isnt ideal for it to be inline. I have opt for compressing lots of the geo types into one GEOS_GEOMETRY to keep it small.

Ideally there is some way for the class to expose extra definitions that can be accessed using $ref.

Alternatively it might be possible to use external schema - I havent checked whether drf-spectacular supports that, and I personally also want to ensure that the validator supports that. When I tried to use an external schema, the field was automatically given readOnly: true which I do not want. I didnt look into whether that was fixable.

@MissiaL
Copy link
Contributor

MissiaL commented Apr 25, 2020

It seems to me that using some other serializers from other packages is not a good idea. You must use the logic of constructing the schema in your project using drf-spectacular

@tfranzel
Copy link
Owner

@jayvdb that looks pretty nice already. you can relatively easily use the ref system:

component = ResolvedComponent(
name=self._get_serializer_name(serializer, direction),
type=ResolvedComponent.SCHEMA,
object=serializer,
)

adapt for your case.

coponent.schema = YOURGISSCHEMA
auto_schema.registry.register(component)
return component.ref

i don't like the external schema idea. i makes sense but i'm pretty sure code generators will choke on that.

@MissiaL could you elaborate why it is not a good idea? there are 3rd party apps that can throw a lot of warnings and their code is not reachable for adaptation if you just use them. in those cases you cannot use @extend_schema and would be forced to override every lib serializer/field with annotation (if even possible).

furthermore, i think it is not a bad idea to support very commonly used packages. the plugin system is specifically designed to have them in contrib so they do not interfere with the core logic.

@MissiaL
Copy link
Contributor

MissiaL commented Apr 25, 2020

Maybe I'm wrong here. I agree with you. Support for popular packages is very good 😊

@jayvdb
Copy link
Contributor Author

jayvdb commented Apr 25, 2020

Great. Thanks for the hints about the component registry; that makes the implementation a lot more clean.

Ideally I would like to store the GeoJSON schema in a file in the package (or finding a canonical/stable versioned copy online), and then loading the file on demand and registering the necessary parts of the schema. That has the benefit of the schema being more accessible/interoperable with other tools, and avoid hidden bugs created in a hand-crafted Pythonised version of the GeoJSON schema.

There are generic JSON fields in Django (and will be cross dbms in Django soon! https://twitter.com/laymonage/status/1242993372819640320), where the app logic decides what data to stuff into them, so some user-friendly mechanism to map a Field(and a field instance) to an external spec will be sorely needed. Due to the problems of external schema & references, "internalising" those external schemas seems to be the way to have your cake and eat it.

@tfranzel
Copy link
Owner

i'm not convinced yet to bloat the package with the GeoJSON schema, but i absolutely get your point. Can we do it without on the first try? if it really makes sense we could still add it later. is that reasonable? not sure yet how to strike a good balance between spectacular being convenient to use and going down the emacs route.

regarding the generic json. that sounds awesome! i had to simulate that on several occations and it would be really good for schemas. once its lands in DRF we definitely going to support that.

@jayvdb
Copy link
Contributor Author

jayvdb commented Apr 25, 2020

Well, we would have the GeoJSON schema either way - either as hand crafted Python objects as per my PR (and my current schema there is very dodgy due to jumbling lots of geo types into a single loose schema using anyOf), or as an external file which we load into Python objects.

I'm happy to continue with the current approach atm, and we can come back to this later when more JSON fields need to be supported. https://www.django-rest-framework.org/api-guide/fields/#jsonfield is already part of DRF. It has historically only been supported with core PostgreSQL django.contrib.postgres.JSONField, but https://pypi.org/search/?q=drf+jsonfield has lots of workarounds people have been using, so you can expect many users are going to be hitting this problem with adoption.

jayvdb added a commit to jayvdb/drf-spectacular that referenced this issue May 1, 2020
Replace custom _map_basic_serializer with _map_field,
and invoke super _map_serializer as a fallback.

DRF AutoSchema PR 7257 makes all of these fields public,
so Spectacular AutoSchema should implement them and use
them when appropriate for interoperability.

Related to tfranzel#31
Related to tfranzel#45
jayvdb added a commit to jayvdb/drf-spectacular that referenced this issue May 1, 2020
Replace custom _map_basic_serializer with _map_field,
and invoke super _map_serializer as a fallback.

DRF AutoSchema PR 7257 makes all of these fields public,
so Spectacular AutoSchema should implement them and use
them when appropriate for interoperability.

Related to tfranzel#31
Related to tfranzel#45
jayvdb added a commit to jayvdb/drf-spectacular that referenced this issue May 1, 2020
Replace custom _map_basic_serializer with _map_field,
and invoke super _map_serializer as a fallback.

DRF AutoSchema PR 7257 makes all of these fields public,
so Spectacular AutoSchema should implement them and use
them when appropriate for interoperability.

Related to tfranzel#31
Related to tfranzel#45
jayvdb added a commit to jayvdb/drf-spectacular that referenced this issue May 3, 2020
Xenial results in
libgdal.so: undefined symbol: OGR_F_GetFieldAsInteger64

Related to tfranzel#31
jayvdb added a commit to jayvdb/drf-spectacular that referenced this issue May 4, 2020
Xenial results in
libgdal.so: undefined symbol: OGR_F_GetFieldAsInteger64

Related to tfranzel#31
jayvdb added a commit to jayvdb/drf-spectacular that referenced this issue May 7, 2020
Xenial results in
libgdal.so: undefined symbol: OGR_F_GetFieldAsInteger64

Related to tfranzel#31
@jayvdb
Copy link
Contributor Author

jayvdb commented May 9, 2020

We should also test django-geoposition , and integrate it into the existing PR. There is also another common one in a package named something like django-extra-fields.
(btw, I'll be getting to this in about a week; a few other fires to put out first)

jayvdb added a commit to jayvdb/drf-spectacular that referenced this issue May 22, 2020
Xenial results in
libgdal.so: undefined symbol: OGR_F_GetFieldAsInteger64

Related to tfranzel#31
jayvdb added a commit to jayvdb/drf-spectacular that referenced this issue May 27, 2020
Xenial results in
libgdal.so: undefined symbol: OGR_F_GetFieldAsInteger64

Related to tfranzel#31
jayvdb added a commit to jayvdb/drf-spectacular that referenced this issue Jun 1, 2020
Xenial results in
libgdal.so: undefined symbol: OGR_F_GetFieldAsInteger64

Related to tfranzel#31
jayvdb added a commit to jayvdb/drf-spectacular that referenced this issue Jun 8, 2020
Xenial results in
libgdal.so: undefined symbol: OGR_F_GetFieldAsInteger64

Related to tfranzel#31
tfranzel pushed a commit that referenced this issue Oct 25, 2020
Xenial results in
libgdal.so: undefined symbol: OGR_F_GetFieldAsInteger64

Related to #31
@tfranzel tfranzel added the help wanted Extra attention is needed label Jan 21, 2021
tfranzel pushed a commit that referenced this issue Jan 22, 2021
Xenial results in
libgdal.so: undefined symbol: OGR_F_GetFieldAsInteger64

Related to #31
@christiaan-dockbite
Copy link

This feature would be very useful

@sayeghr
Copy link

sayeghr commented Mar 9, 2021

Love the library, just want to +1 the sentiment that this feature would be very useful.

@SidneyNiccolson
Copy link

Also would love to have this feature (+1)!

@AJ-BM
Copy link

AJ-BM commented Sep 16, 2021

I would also love support for Djangos GeometryField

@tfranzel
Copy link
Owner

thank you very much for the feedback and the appreciation!

I myself am not a user of django-rest-framework-gis. Due to time constraints I am focusing on fixing issues in the core system at the moment. I simply lack the time to implement this or negotiate a solution with upstream.

It is possible that openwisp/django-rest-framework-gis/pull/223 gives us the required facilities, but I have not studied it in detail. @jayvdb may chime in on this and comment on whether there are any road blocks left. If anyone is attempting to do this, make sure you also read up on #38.

@christiaan-dockbite
Copy link

@tfranzel I am confused why #38 cannot be merged. I would be very happy with the feature, so I am happy to contribute to it. I do not know however where to start. Can you give some explanation on this?

tfranzel pushed a commit that referenced this issue Sep 21, 2021
Xenial results in
libgdal.so: undefined symbol: OGR_F_GetFieldAsInteger64

Related to #31
@tfranzel
Copy link
Owner

hey @christiaan-dockbite

I stopped working on it because it received little feedback and most importantly I did not want to cannibalize @jayvdb efforts. #67 served merely as basis for discussion. i just rebased it from time to time, which I just did again. @jayvdb offered to pick it up again, but gave no signals since then. i guess it's up for grabs.

Then openwisp/django-rest-framework-gis/pull/223 updated their schema support, which is quite frankly a ridiculous upstream decision. The gist is that every lib is supposed to write their own AutoSchema. Not quite sure how that was ever supposed to work with more than 1 non-trivial library, but i digress.

The remaining question is basically this:
Do we bother extracting their schema from openwisp/django-rest-framework-gis/pull/223 or is our generic approach sufficient?We basically took the GeoJSON definition and massaged it a bit. I have no idea if django-rest-framework-gis completely adheres to the GeoJSON standard.

@Christiaanvv
Copy link

@tfranzel see #532

@ThalusA
Copy link

ThalusA commented May 6, 2022

This is still not fix ?

@tfranzel
Copy link
Owner

finally resolved by #746.

The new approach is forked from django-rest-framework-gis but adapted to our needs including some bugfixes. The reasoning behind this is that the AutoSchema subclassing approach was rendered obsolete by DRF's maintainers.

@tfranzel tfranzel added the fix confirmation pending issue has been fixed and confirmation from issue reporter is pending label May 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request fix confirmation pending issue has been fixed and confirmation from issue reporter is pending help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants