diff --git a/src/openforms/prefill/__init__.py b/src/openforms/prefill/__init__.py index 177a8e13b4..6fb673f72a 100644 --- a/src/openforms/prefill/__init__.py +++ b/src/openforms/prefill/__init__.py @@ -81,7 +81,11 @@ def invoke_plugin( if values: logevent.prefill_retrieve_success(submission, plugin, fields) else: - logevent.prefill_retrieve_empty(submission, plugin, fields) + if (required_attribute := plugin.requires_auth) is None or ( + (auth_info := getattr(submission, "auth_info", None)) + and auth_info.attribute == required_attribute + ): + logevent.prefill_retrieve_empty(submission, plugin, fields) return plugin_id, identifier_role, values diff --git a/src/openforms/prefill/tests/test_prefill_hook.py b/src/openforms/prefill/tests/test_prefill_hook.py index b63968c8c8..86285b2a25 100644 --- a/src/openforms/prefill/tests/test_prefill_hook.py +++ b/src/openforms/prefill/tests/test_prefill_hook.py @@ -627,3 +627,36 @@ class TestPlugin(BasePlugin): result = plugin.get_identifier_value(submission, IdentifierRoles.main) self.assertEqual("123123123", result) + + def test_prefill_logging_with_mismatching_login_method(self): + components = [ + { + "key": "mainPersonName", + "type": "textfield", + "prefill": { + "plugin": "demo", + "attribute": "naam.voornamen", + "identifierRole": IdentifierRoles.main, + }, + }, + ] + submission = SubmissionFactory.from_components( + components_list=components, kvk="69599084" + ) + register = Registry() + + @register("demo") + class MismatchPlugin(DemoPrefill): + requires_auth = AuthAttribute.bsn + + @classmethod + def get_prefill_values(cls, submission, attributes, identifier_role): + return {} + + apply_prefill( + configuration={"components": components}, + submission=submission, + register=register, + ) + + self.assertFalse(TimelineLogProxy.objects.exists())