-
Notifications
You must be signed in to change notification settings - Fork 27
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
LiteratureBuilder: avoid adding empty fields #135
Comments
This is a conscious design decision. @david-caro wanted the buillder to be dumb, @jacquerie to be smart and do validation. I think it would make more sense for the builder to do validation of the subfields, i.e. the builder would contain def __init__(self, source, record=None):
# other init
self.schema = load_schema('hep')
def add_language(...):
# do whatever it is doing now
validate(self.record['languages'], self.schema['properties']['languages']) |
In principle I was thinking that I created this issue because one of the workflows failed because we did (I don't know how): builder.add_language('') Amending filter_empty_parameters would have avoided this issue (adding the validation the form would have crashed for the user) |
that function filters out empty In [1]: from inspire_schemas.builders import LiteratureBuilder
In [2]: x = LiteratureBuilder(source='arXiv')
In [3]: x.add_language(language='')
In [4]: x
Out[4]: LiteratureBuilder(source="arXiv", record={})
In [5]: x.add_language('')
In [6]: x
Out[6]: LiteratureBuilder(source="arXiv", record={'languages': ['']}) |
It probably is a bug in the builder though. @rikirenz, what do you think? |
Yep, maybe |
What is the conclusion of this issue? |
Discussing IRL with @rikirenz and @jacquerie, we figured out it made more sense to filter everything for now. But maybe the whole approach of the builder should be rethought to be generated automatically from the schema (@jacquerie might explain more). This problem was partially solved (only for empty fields in lists) by the |
Automatic generation from the schema will make the builder to change everytime the schema change, thus hindering the very purpose of the builder abstraction. What am I missing? |
We were thinking about a way to create the actual builder directly from the schema. This implies to write a sort of compiler that is able to derive the builder from the schema. It is a cool idea but definitely is not a priority. |
You mean a way to kickstart a builder once, and then maintain it by hand, then, correct? |
Well the compiler should be able to derive the builder every time that we do a change. It means that if the compiler is well written we should not touch the builder anymore. |
Anyway before to fix this issue I open this #142. Because I am quite afraid to change the decorator filter without regression tests. For this reason from the moment that this issue it seems not so urgent, I would like to write the tests for the builder before and after fix this. |
Depends #142 |
I am not understanding how the interface of the builder can remain stable if the builder is automatically generated from a changing schema. Anyway since this is not a priority, no need to convince me now 👍 |
The text was updated successfully, but these errors were encountered: