Possible Bug: Two publish event webhooks fired in quick succession. One with the previous field values and one with the newly changed field values

I was debugging why the data we had in one system did not match the data we had in DatoCMS for a particular record in our “Offer” model. I determined that our system had the correct information (expiration_datetime) and had the system update the record in Dato using the content management API with the correct data and then publish those changes. It did correctly update the record in the model, but two publish webhook events fired:

The first one had the old expiration_datetime field value of “2024-12-31T23:59:00-05:00”. Here is the meta data for that webhook:

"webhook_call_id": "137271943",
  "event_triggered_at": "2025-02-17T20:42:29Z",
  "attempted_auto_retries_count": 0,
  "webhook_id": "27338",
  "site_id": "xxxxx",
  "environment": "main",
  "is_environment_primary": true,
  "entity_type": "item",
  "event_type": "publish"

The next publish webhook had the correct value for the expiration_datetime field of “2024-12-30T08:58:02-05:00”
Here is the meta data for that webhook request:

"webhook_call_id": "137271949",
  "event_triggered_at": "2025-02-17T20:42:29Z",
  "attempted_auto_retries_count": 0,
  "webhook_id": "27338",
  "site_id": "xxxxx",
  "environment": "main",
  "is_environment_primary": true,
  "entity_type": "item",
  "event_type": "publish",

Why would we receive two of these requests? And why would one contain the wrong data? I’ve excluded the full webhook payload because it can be quite large. But, I can provide it if needed.

I’ve just witnessed this happen with another record. Also the expiration_datetime field:

Meta data of webhook with incorrect field value:

"webhook_call_id": "137274685",
  "event_triggered_at": "2025-02-17T21:34:30Z",
  "attempted_auto_retries_count": 0,
  "webhook_id": "27338",
  "site_id": "xxxxx",
  "environment": "main",
  "is_environment_primary": true,
  "entity_type": "item",
  "event_type": "publish",

Meta data of webhook payload with the correct value:

"webhook_call_id": "137274689",
  "event_triggered_at": "2025-02-17T21:34:31Z",
  "attempted_auto_retries_count": 0,
  "webhook_id": "27338",
  "site_id": "xxxxx",
  "environment": "main",
  "is_environment_primary": true,
  "entity_type": "item",
  "event_type": "publish",

Hi @jearle,

With webhook calls 137271943 and 137271949, it looks like there were actually some changes? Can you try running the two of them through a diff and see if those are intentional?

For example, the system_facets field was null in 137271943 and became an array of record links in 137271949. A few other fields (legacy_id, tracking, and content also changed).

Is this something your script might be doing? If it’s changing relationships, is it possible that it’s causing some cascading changes?

I don’t want to dive into your private schema here in public, but if you can’t figure it out based on a diff, could you please email us at support@datocms.com with some details about the use case here (like how your script interacts with this model and its related fields).

Thank you!

Actually, another hint:

meta.status was updated for 137271943, and published for 137271949.

Was this webhook previously set up to run on both publish and update?

It’s the same situation with 137274685 vs 137274689: similar changed fields, the older one was an updated and the newer one was a published.

It’s strange… normally, update and publish are two different lifecycle events (corresponding to those same meta statuses): https://www.datocms.com/docs/general-concepts/webhooks#lifecycle-events-with-draft-pub-enabled

But in your case, somehow you were able able to trigger an updated state from a publish event. I’m not sure how that is happening. :thinking:

Can you please DM or email us the script that’s doing this so I can take a closer look…?