-
Notifications
You must be signed in to change notification settings - Fork 73
‼️ Improve needs default field application (via needs_global_options) #1478
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
Conversation
Previously defaults would be applied to any fields of a need with a "falsy" value, e.g. `None`, `False`, `0` , `""`, `[]`. ... This is an issue, if the user want to specifically set fields to these values, without them being overriden by defaults. Therefore, now defaults are only applied to fields with a missing value, denoted by `None`. In the need directive context, this means that defaults will only be set for fields not specifically specified in the directive. In the external/import need context, defaults will only be applied to missing fields, of fields with the value `null`. TODO discuss restriction of predicate filtering fields, and that these field values will no longer be based on previous default applications.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1478 +/- ##
==========================================
+ Coverage 86.87% 89.01% +2.13%
==========================================
Files 56 67 +11
Lines 6532 8277 +1745
==========================================
+ Hits 5675 7368 +1693
- Misses 857 909 +52
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
TLDR: I approve of this PR. This requires some thoughts. It feels like the start of some decisions that have to be made for a stable future. Affected components:
Generally in programming, there is the notion of
To explore how this could be modeled in RST and JSON, we can look at the following examples. Considering an RST directive and the fields
Unbound / missing fields.. req:: Unbound / missing fields
:id: REQ_1 Option 1 for representation in JSON: {
"id": "REQ_1",
"title": "Unbound / missing fields",
} Option 2 for representation in JSON: {
"id": "REQ_1",
"title": "Unbound / missing fields",
"opt_string": null,
"opt_bool": null,
"opt_int": null,
"opt_float": null,
"opt_list": null,
"links": null
} Problem with undefined unbound fields is they are problematic in filter strings. Given but undefined / empty fields.. req:: Given but undefined / empty
:id: REQ_1
:opt_string:
:opt_bool:
:opt_int:
:opt_float:
:opt_list:
:links: Option 1 for representation in JSON: {
"id": "REQ_1",
"title": "Given but undefined / empty",
"opt_string": null,
"opt_bool": null,
"opt_int": null,
"opt_float": null,
"opt_list": null,
"links": null
} Option 2 for representation in JSON: {
"id": "REQ_1",
"title": "Given but undefined / empty",
"opt_string": "",
"opt_bool": false,
"opt_int": 0,
"opt_float": 0.0,
"opt_list": [],
"links": []
} Option 3 for representation in JSON: {
"id": "REQ_1",
"title": "Given but undefined / empty",
"opt_string": "",
"opt_bool": null,
"opt_int": null,
"opt_float": null,
"opt_list": [],
"links": [],
} This is a tricky one. Certainly users do not want to see a Option 1 is problematic as the 'given' semantics is lost (no difference to unbound fields). Option 2 is problematic as string fields, list options and link fields cannot be For these reasons I prefer the type specific handling in option 3 here. Given with falsy value.. req:: Given with falsy value
:id: REQ_1
:opt_string:
:opt_bool: false
:opt_int: 0
:opt_float: 0.0
:opt_list: There is only one representation in JSON: {
"id": "REQ_1",
"title": "Given with falsy value",
"opt_string": "",
"opt_bool": false,
"opt_int": 0,
"opt_float": 0.0,
"opt_list": []
} Observations / statements / proposalThe statements assume
|
Well, this is a problem with the current filter strings, if evaluated by Python. In jinja m, for example, there is a handling of undefined values. |
In most databases, sqllite etc, you can specify if the field is allowed to be nullable, should this not be the case for requirements? |
Nullable makes total sense for information not given. Agree. |
Previously defaults would be applied to any fields of a need with a "falsy" value, e.g.
None
,False
,0
,""
,[]
. ...This is an issue, if the user wants to specifically set fields to these values, without them being overridden by defaults. Therefore, now defaults are only applied to fields with a missing or
None
value.In the need directive context, this means that defaults will only be set for fields not specifically set in the directive options.
In the external/import need context, defaults will only be applied to missing keys in the
needs.json
, or fields with the value set tonull
.For predicate defaults, the context passed to the expression has been restricted to a subset of fields, and these values are no longer mutated by previous defaults, i.e. each predicate gets the same immutable context data.
This makes these predicates more isolated / understandable, and allows for them potentially later being co-located with the type information.
This PR may be breaking:
For users expecting defaults to be applied to external/import
needs.json
, although I would suggest this was never the intention for these defaults and thatneeds.json
should, at least by default, be seen as static ingest data which has already had defaults etc applied.For users with "exotic" predicate expressions, that potentially rely on the application of previous defaults.