-
-
Notifications
You must be signed in to change notification settings - Fork 269
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
add support for TinyDB feature provider #1724
Conversation
FYI the associated CITE instance PR can be merged if/once this is approved/merge. |
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.
Two main comments:
- refactor Catalogue-specific statements into subclass
TinyDBCatalogueProvider
- add also unit tests for
TinyDBCatalogueProvider
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.
There are quite some if self._catalogue
statements in the base class TinyDBProvider
, while at the same time there is a subclass TinyDBCatalogueProvider
. My suggestion is to refactor those conditionals into the subclass.
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.
That was my original implementation, but I decided to add this conditional (3x) in the code so as not to have to loop after search results which would affect performance.
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.
But you may use overloaded functions and make _excluded a class var extended in. See rough example attached:
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.
(maybe not use return values, but like:
def _add_text_search_field(self, fields):
fields['q'] = {'type': 'string'}
// return fields
Note that these already exist in |
@justb4 PR updated, for review. |
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.
See inline comments: think all will be resolved by simply removing self.fields = self.get_fields()
from constructor.
def __init__(self, provider_def): | ||
super().__init__(provider_def) | ||
|
||
self._excludes = ['_metadata-anytext'] |
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.
Major: IMO will not have desired effect: self.fields = self.get_fields()
is already called in the base class constructor. Or self.fields = self.get_fields()
should be called again, but see my suggestion to make _excludes
a class var as it is in effect a property of the classes.
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.
To consider: self.fields
is never referenced after assignment so maybe self.fields = self.get_fields()
can be removed and the above self._excludes =
-statement will be ok. get_fields()
is a Provider base.py method and the way to access fields I guess.
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.
If we remove self.fields = self.get_fields()
from the constructor then this will affect other parts of pygeoapi.api.itemtypes
. Suggest we leave this as is in this PR and address in a subsequent PR later on.
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.
Ok, then the only remaining is IMO to resolve the proper _excludes
.
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.
Do you agree that the current order will not work? Hence my suggestion for a class var (see my example) or another solution? i.e. get_fields()
will not include self._excludes = ['_metadata-anytext']
as it is set after the parent class constructor. Reversing will also not work, as it will be overridden as self._excludes = []
in base class. (That is why I usually do not recommend too much initialization in a constructor, but explicit init/lifecycle methods.)
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.
The default TinyDB provider as a result of this PR has an empty _excludes
member. The TinyDBCatalogue provider sets _excludes
to remove a given property that is a pygeoapi "extra".
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.
fwiw other providers make the call to self.get_fields()
at the end of the init method which will either fetch self.fields if set, or set self.fields.
Happy to establish a normative behavior between the two implementations. self.fields = self.get_fields()
is present in
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.
Good points. Suggest we address this as part of another PR
def __init__(self, provider_def): | ||
super().__init__(provider_def) | ||
|
||
self._excludes = ['_metadata-anytext'] |
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.
Do you agree that the current order will not work? Hence my suggestion for a class var (see my example) or another solution? i.e. get_fields()
will not include self._excludes = ['_metadata-anytext']
as it is set after the parent class constructor. Reversing will also not work, as it will be overridden as self._excludes = []
in base class. (That is why I usually do not recommend too much initialization in a constructor, but explicit init/lifecycle methods.)
@justb4 this order works and accomplishes the need to remove the specified fields from catalogue responses. |
Hmm, I still don't think so. Here is a similar example I used to investigate, showing both the instance and class var:
|
@justb4 feel free to test the branch with/without the exclude in the TinyDBCatalogue class? |
Ok, all tests pass. But makes sense as
as it results from constructor, the field is not excluded and test fails:
'_metadata-anytext' is not excluded... as can be expected. |
By using the class var, and an extra test, all is now well. Shall I commit/push my version on this branch? |
What if we normalized all access via |
Function access is always to be preferred over exposing internal instance vars. But harder to assess (performance) impact. As for some Providers it may mean accessing a remote source like a DB or even WFS. But then again
|
I guess you mean: @property
def fields(self):
return self.get_fields() Suggest we address as part of another PR (given the scope of this PR is to expand TinyDB support). While we've identified some inconsistency/issue with @justb4 works for you? |
Ok, yes, but in my code I meant to cache the fields on first access (or leave that to each provider). Still in the current state |
I think there is no impact in the context of the codepath and how the plugin is implemented. |
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.
Ok, we'll fix 'excluds' issue later. For sake of progress.
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.
Nice job!
Overview
Add support for TinyDB as a feature provider.
Additionally updates CITE test setup and docs.
Related Issue / discussion
Fixes #1723
Additional information
Dependency policy (RFC2)
Updates to public demo
Contributions and licensing
(as per https://github.com/geopython/pygeoapi/blob/master/CONTRIBUTING.md#contributions-and-licensing)