Skip to content

Commit

Permalink
🎨 [#4396] Simplify code execution branches
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sergei-maertens committed Oct 25, 2024
1 parent 9590a47 commit 881af98
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions src/openforms/prefill/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,19 +170,12 @@ def prefill_variables(submission: Submission, register: Registry | None = None)
total_config_wrapper = submission.total_configuration_wrapper
for variable_key, prefill_value in prefill_data.items():
if key_source_mappings[variable_key] == FormVariableSources.component:
try:
component = total_config_wrapper.component_map[variable_key]
except KeyError:
return None

component = total_config_wrapper[variable_key]
normalized_prefill_value = normalize_value_for_component(
component, prefill_value
)
variable = state.get_variable(variable_key)
variable.value = normalized_prefill_value
prefill_data[variable_key] = normalized_prefill_value
elif key_source_mappings[variable_key] == FormVariableSources.user_defined:
prefill_data[variable_key] = prefill_value
prefill_value = normalized_prefill_value

prefill_data[variable_key] = prefill_value

state.save_prefill_data(prefill_data)

0 comments on commit 881af98

Please sign in to comment.