From 90c285982f11b93f12af1f3c7856df62b43ee05a Mon Sep 17 00:00:00 2001 From: Graham Beckley Date: Wed, 13 Dec 2023 10:46:18 -0500 Subject: [PATCH] Allow coercion of numbers to strings in `BugzillaWebhookEventChange` Fixes https://mozilla.sentry.io/issues/4709636996/ --- jbi/models.py | 2 ++ tests/unit/test_models.py | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/jbi/models.py b/jbi/models.py index 77f37f9d..faf89706 100644 --- a/jbi/models.py +++ b/jbi/models.py @@ -175,6 +175,8 @@ class BugzillaWebhookUser(BaseModel): class BugzillaWebhookEventChange(BaseModel): """Bugzilla Change Object""" + model_config = ConfigDict(coerce_numbers_to_str=True) + field: str removed: str added: str diff --git a/tests/unit/test_models.py b/tests/unit/test_models.py index 551f08b6..5e6abc06 100644 --- a/tests/unit/test_models.py +++ b/tests/unit/test_models.py @@ -174,6 +174,17 @@ def test_payload_changes_list(webhook_event_change_factory, webhook_event_factor ] +def test_payload_changes_coerces_numbers_to_strings( + webhook_event_change_factory, webhook_event_factory +): + changes = [ + webhook_event_change_factory(field="is_confirmed", removed="1", added=0), + ] + event = webhook_event_factory(routing_key="bug.modify", changes=changes) + assert event.changed_fields() == ["is_confirmed"] + assert event.changes[0].added == "0" + + def test_max_configured_projects_raises_error(action_factory): actions = [action_factory(whiteboard_tag=str(i)) for i in range(51)] with pytest.raises(pydantic.ValidationError):