-
Notifications
You must be signed in to change notification settings - Fork 26
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
[#4396] Objects API prefill plugin #4620
[#4396] Objects API prefill plugin #4620
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #4620 +/- ##
==========================================
- Coverage 96.57% 96.55% -0.02%
==========================================
Files 746 748 +2
Lines 25271 25399 +128
Branches 3332 3354 +22
==========================================
+ Hits 24406 24525 +119
- Misses 602 609 +7
- Partials 263 265 +2 ☔ View full report in Codecov by Sentry. |
66ed5a5
to
482bc20
Compare
0ee299f
to
2b992bf
Compare
2b6a3f0
to
8eb07c9
Compare
2b992bf
to
50c9377
Compare
8eb07c9
to
0d9f00c
Compare
50c9377
to
70f0382
Compare
0d9f00c
to
b7e03db
Compare
7ac1670
to
71cc7e8
Compare
70f0382
to
0dfe280
Compare
7b222b9
to
59304cb
Compare
a7c3df4
to
e60e61c
Compare
0b5b2cd
to
1a4c02c
Compare
1a4c02c
to
110283f
Compare
050232d
to
cf2bb25
Compare
cf2bb25
to
13938ae
Compare
25a6f91
to
2890501
Compare
2890501
to
ac6c7a4
Compare
# we are creating a new step below-no need for two steps | ||
self.form.formstep_set.get().delete() | ||
FormStepFactory.create( | ||
form=self.form, | ||
form_definition=self.step.form_definition, | ||
prefill_plugin="demo", | ||
prefill_attribute="random_string", | ||
form_definition__configuration={ | ||
"components": [ | ||
{ | ||
"type": "textfield", | ||
"key": "test-key", | ||
"label": "Test label", | ||
"prefill": {"plugin": "demo", "attribute": "random_string"}, | ||
} | ||
] | ||
}, |
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.
does this result in the same variable being created?
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 realized that in the way we test things here (getting the submission variables by SubmissionValueVariable.objects.filter(submission=submission)
)gives us one submission variable when the form variables are two. I would do it with submission.load_submission_value_variables_state()
tbh which gives 2. I am a bit confused here..
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 traced back why the additional variable was created and patched that behaviour, so the test changes are reverted too :)
dd39aa2
to
e9de058
Compare
if not (prefill := component.get("prefill")): | ||
continue | ||
if not prefill.get("plugin"): | ||
continue | ||
if not prefill.get("attribute"): | ||
continue |
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.
Lines were not covered before the code was moved, accepting this as-is and I'm ignoring the codecov annotations.
…lugin for ObjectsApi
Seems to pass the tests and simplifies the code a little. The try-except should not happen because of the way form variables are created/synced from formio definitions, and if it happens, we want to be notified of it via error monitoring. Additionally, we can apply the post-processing special treatment for component sources, and leave the default behaviour for everything else, rather than potentially missing some cases if additional sources get added in the future. The variable itself is already mutated during the saving of prefill data, so just updating the dict holding the [key, value] pairs is sufficient.
e9de058
to
b15f080
Compare
src/openforms/prefill/service.py
Outdated
try: | ||
component = total_config_wrapper.component_map[variable_key] | ||
except KeyError: | ||
return None |
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.
This looks a bit weird - if something is wrong we seem to discard everything. Does that make sense? The lack of coverage on the error handling also makes this seem like a what-if.
This could occur if someone manually creates a FormVariable
in the admin/shell without it being backed by an actual form definition component, which shouldn't happen. The API endpoint synchronizes the components and derived variables, so I'm leaning towards removing the try-except and if it crashes, it crashes and at least it will become visible in Sentry instead of failing silently, no?
In the old situation this wouldn't happen anyway because we looped only over the prefill variables.
# we are creating a new step below-no need for two steps | ||
self.form.formstep_set.get().delete() | ||
FormStepFactory.create( | ||
form=self.form, | ||
form_definition=self.step.form_definition, | ||
prefill_plugin="demo", | ||
prefill_attribute="random_string", | ||
form_definition__configuration={ | ||
"components": [ | ||
{ | ||
"type": "textfield", | ||
"key": "test-key", | ||
"label": "Test label", | ||
"prefill": {"plugin": "demo", "attribute": "random_string"}, | ||
} | ||
] | ||
}, |
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 traced back why the additional variable was created and patched that behaviour, so the test changes are reverted too :)
Closes #4396 partially
Changes
prefill_options
to theFormVariable
model (for storing all the needed configuration) and updated constraints according to new fieldprefill.service
Checklist
Check off the items that are completed or not relevant.
Impact on features
Release management
I have updated the translations assets (you do NOT need to provide translations)
./bin/makemessages_js.sh
./bin/compilemessages_js.sh
Commit hygiene