# Page crashes when updating field

**URL:** <https://forum.getkirby.com/t/page-crashes-when-updating-field/34655>\
**Category:** Questions\
**Tags:** v5\
**Created:** [August 27, 2025, 12:14pm UTC](https://forum.getkirby.com/t/page-crashes-when-updating-field/34655 "2025-08-27T12:14:09Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![hemorej](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/hemorej/32/7724_2.png) [@hemorej](https://forum.getkirby.com/u/hemorej)\
**Post date:** [August 27, 2025, 12:14pm UTC](https://forum.getkirby.com/t/page-crashes-when-updating-field/34655/1 "2025-08-27T12:14:10Z")

</div>

I have a product blueprint with an external ID field for the corresponding product in Stripe. I wrote a page update hook to handle the Stripe side. The problem occurs at the very last step when I need to update the local product with that field, I’m unable to save it

If I simply use `$page->update( [$field => $fieldData] );` I get this error

 ![Screenshot 2025-08-27 at 07.49.21](https://europe1.discourse-cdn.com/flex017/uploads/getkirby/original/3X/e/e/eea4612170f1156726dca2a164d65f9eaee5c051.png)

Worse still, it completely wipes the saved content file after that and I lose everything.

I tried using `impersonate` with either the authenticated user or the superuser kirby instead to see if it helps, I get this instead (and it also wipes the content file after)

 ![Screenshot 2025-08-27 at 07.59.27](https://europe1.discourse-cdn.com/flex017/uploads/getkirby/original/3X/2/5/25e8828f0896c86695e291b72317ded0f40013d0.png)

Hook config:

```php
	'hooks' => [
		'page.update:after' => function ( $newPage, $oldPage = null ) {
			$updateHandler = new PageUpdateHandler();
			$updateHandler->handle( $newPage, $oldPage );
		},
	],

```

Update code in the handler: (complete code [here](https://github.com/hemorej/invis/blob/master/site/plugins/payments/src/StripeConnector.php#L200))

```php
kirby()->impersonate( kirby()->user() ); // with or without this part
$product->parent()->update(['external_id' => $productStripeId]);

```

Template: (full template [here](https://github.com/hemorej/invis/blob/master/site/blueprints/pages/product.yml))

```yaml
          external_id:
            type: text
            label: External Price ID
            help: Auto-generated ID from payment system, leave blank
            translate: false

```

---

<div class="post-metadata">

**Author:** ![hemorej](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/hemorej/32/7724_2.png) [@hemorej](https://forum.getkirby.com/u/hemorej)\
**Post date:** [August 27, 2025, 3:43pm UTC](https://forum.getkirby.com/t/page-crashes-when-updating-field/34655/2 "2025-08-27T15:43:33Z")

</div>

I should add that if I update the field value manually in the panel UI it works fine, something about the programmatic update in the backend I can’t figure out

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [August 27, 2025, 4:21pm UTC](https://forum.getkirby.com/t/page-crashes-when-updating-field/34655/3 "2025-08-27T16:21:02Z")

</div>

Hard to tell if and what is going wrong. To start debugging this, I would first try a manual update (without any impersonated user) directly from the hook:

```auto
'hooks' => [
		'page.update:after' => function ( $newPage, $oldPage = null ) {
			$newPage->update(['external_id' => 'somevalue']);
			
		},
	],

```

If that works, debug your code step by step.

---

<div class="post-metadata">

**Author:** ![hemorej](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/hemorej/32/7724_2.png) [@hemorej](https://forum.getkirby.com/u/hemorej)\
**Post date:** [August 27, 2025, 6:31pm UTC](https://forum.getkirby.com/t/page-crashes-when-updating-field/34655/4 "2025-08-27T18:31:24Z")

</div>

I think I found the issue, this only happens when I’m updating two fields on the page through the hook in one save action. If I try to perform one update at a time it works, if both fields are modified and need to be saved then this happens.

Is there a way to “commit” the first change when I call `update([])` before I invoke it a second time later on ?

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [August 27, 2025, 7:09pm UTC](https://forum.getkirby.com/t/page-crashes-when-updating-field/34655/5 "2025-08-27T19:09:10Z")

</div>

Objects are immutable in Kirby. So say you do

```auto
$page->update();

```

And want to update that object again later, you first need to store it in a variable.

```auto
$page = $page->update();

```

Then use the new page for the next update step.

---

<div class="post-metadata">

**Author:** ![hemorej](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/hemorej/32/7724_2.png) [@hemorej](https://forum.getkirby.com/u/hemorej)\
**Post date:** [August 30, 2025, 3:25pm UTC](https://forum.getkirby.com/t/page-crashes-when-updating-field/34655/6 "2025-08-30T15:25:44Z")

</div>

I’ve just tried that but it still won’t allow me the second update.

The second update is updating a field on a nested YAML structure on the main object, and I’m passing the `$page` variable to a utility function to perform that update. Is it possible any of that prevents further updates?

I’ve also tried fetching a new page instance before the second update like this `page(‘my-page-name’)→update(['subfield' => ‘value’]);` to no effect
