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
Refs #23804 -- RasterField initialization only if HAS_GDAL #4905
Conversation
I don't mind the definition split. But I'm not so enthusiast about conditionally importing some Field. Past personal experiences have shown that this can lead to surprising or hard-to-debug failures.
|
If conditional imports of fields are a bad idea, then splitting the fields module is not necessary. So I just updated the pull request with a similar idea based on @claudep 's patch. For the field, GDAL is only required for instantiating the spatial proxy (GDALRaster object). So why not just allow returning the raw data and bypass the lazy instantiation? |
661d9e2
to
a1cc9e2
Compare
Maybe it would be worth adding a test for the error that runs on systems without GDAL? Also, let's reference the original ticket (#23804) rather than the new one. "Ref -> Refs" in message. |
I simplified the patch a bit more and tried to add a test for this, but I did not find a way to make |
I was thinking that the test would only run on systems without GDAL installed so there wouldn't be a need to mock HAS_GDAL. |
c0a8e30
to
a2ef30b
Compare
Ok, here is a more viable solution. The |
@@ -405,6 +405,11 @@ class RasterField(BaseSpatialField): | |||
description = _("Raster Field") | |||
geom_type = 'RASTER' | |||
|
|||
def __init__(self, **kwargs): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to accept *args here too (or at least at verbose_name=None
. There's a convention to pass verbose_name
as a positional arg: https://docs.djangoproject.com/en/1.8/topics/db/models/#verbose-field-names
Add a test for that too?
Claude, is this approach fine with you?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, sounds good. And +1 for the positional argument. (_args, *_kwargs) doesn't cost much.
71c3143
to
6be5bdd
Compare
Added |
merged in c0fff64, thanks! |
The automatic instantiation of GDALRaster instances on field values fails if gdal is not installed.