Skip to content

Fix PATCH /api/application/nodes returning 500 due to null timestamps#2286

Open
NeilHanlon wants to merge 1 commit intopelican-dev:mainfrom
neil-forks:fix/node-patch-500-null-timestamp
Open

Fix PATCH /api/application/nodes returning 500 due to null timestamps#2286
NeilHanlon wants to merge 1 commit intopelican-dev:mainfrom
neil-forks:fix/node-patch-500-null-timestamp

Conversation

@NeilHanlon
Copy link
Copy Markdown

The NodeUpdateService uses replicate() to create a copy of the node model before updating it. replicate() strips timestamp fields, and after forceFill()->save(), the in-memory model still has null values for created_at and updated_at. When the NodeTransformer calls formatTimestamp() on these null values, it triggers a TypeError because the method expects a non-nullable string.

Adding refresh() after save() reloads the model from the database, ensuring timestamps are properly populated before the response is serialized.

This was discovered when attempting to programmatically update nodes using the API, which reliably reproduces the following error:

App\Transformers\Api\Application\BaseTransformer::formatTimestamp(): Argument #1 ($timestamp) must be of type string, null given, called in /var/www/pelican/app/Transformers/Api/Application/NodeTransformer.php on line 36 {"userId":2,"exception":"[object] (TypeError(code: 0): App\\Transformers\\Api\\Application\\BaseTransformer::formatTimestamp(): Argument #1 ($timestamp) must be of type string, null given, called in /var/www/pelican/app/Transformers/Api/Application/NodeTransformer.php on line 36 at /var/www/pelican/app/Transformers/Api/Application/BaseTransformer.php:109)

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 29, 2026

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 29, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: bcbf5020-f06c-4930-bad7-7270c4c27ca6

📥 Commits

Reviewing files that changed from the base of the PR and between ef7f79a and 0e60153.

📒 Files selected for processing (1)
  • app/Services/Nodes/NodeUpdateService.php
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/Services/Nodes/NodeUpdateService.php

📝 Walkthrough

Walkthrough

The NodeUpdateService was changed to inject explicit created_at (from the original node) and updated_at (set to now()) into the data before calling forceFill(...)->save(), causing those timestamp fields to be persisted with the supplied values.

Changes

Cohort / File(s) Summary
Timestamps injected on update
app/Services/Nodes/NodeUpdateService.php
Augments $data before persisting by setting created_at to the source node's created_at and updated_at to now() prior to calling forceFill(...)->save(), causing explicit timestamps to be written on the updated record.
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main issue being fixed: a 500 error in the PATCH API endpoint caused by null timestamps.
Description check ✅ Passed The description provides a clear explanation of the problem, root cause, solution, and the specific error encountered, directly related to the changeset.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@NeilHanlon
Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

Comment thread app/Services/Nodes/NodeUpdateService.php Outdated
The NodeUpdateService uses replicate() to create a copy of the node
model before updating it. replicate() strips timestamp fields, and
after forceFill()->save(), the in-memory model still has null values
for created_at and updated_at. When the NodeTransformer calls
formatTimestamp() on these null values, it triggers a TypeError
because the method expects a non-nullable string.

Adding refresh() after save() reloads the model from the database,
ensuring timestamps are properly populated before the response
is serialized.
@NeilHanlon NeilHanlon force-pushed the fix/node-patch-500-null-timestamp branch from ef7f79a to 0e60153 Compare April 14, 2026 01:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants