Repository navigation
Description
Describe the Bug
When creating a new document in an upload-enabled collection (e.g. when uploading a file), the url and thumbnailURL fields are not stored in the database.
Only after saving the document again (for example, when updating the alt text), the url is persisted to the database.
This happens both without using any storage adapter and when using any of the storage adapters. It also affects the url field of image sizes.
By looking at Payload’s source code for uploads, I noticed that the default url field (as well as thumbnailURL and the url fields for image sizes) automatically get an afterRead hook attached, which calls the generateURL function.
This explains why the url is stored in the database only after the first update — because during the read operation from the database, the url is generated based on the filename, then present in the document on save, and therefore persisted.
Expected behaviour
The url fields should either never be stored in the database (virtual field) or always be stored consistently.
Actual behaviour
The url fields are not stored in the database on upload, but they are persisted after the first update.
Possible solution
It would make sense to add virtual: true to the url fields that are automatically created by Payload.
Otherwise, if someone enables disablePayloadAccessControl when there are already images in the database, all URLs in the database would incorrectly point to /api/media instead of the actual file source.
More context
I noticed this issue because sometimes my custom adminThumbnail function received the originalDoc with a url field set and sometimes not, which is caused by this inconsistency.
Reproduction video
2025-11-11.11-23-27.mp4
Link to the code that reproduces this issue
Reproduction Steps
- run the Payload app of the linked reproduction repository (blank template without any storage adapters or the payload-cloud plugin)
- create a new media document by uploading a file
- inspect the URL field in the database (it's not present)
- update the media document (e.g. update the alt text)
- inspect the URL field in the database (it's present now).
Which area(s) are affected? (Select all that apply)
area: core
Environment Info
Binaries:
Node: 24.3.0
npm: 11.4.2
Yarn: N/A
pnpm: 10.12.4
Relevant Packages:
payload: 3.63.0
next: 15.4.7
@payloadcms/db-mongodb: 3.63.0
@payloadcms/graphql: 3.63.0
@payloadcms/next/utilities: 3.63.0
@payloadcms/richtext-lexical: 3.63.0
@payloadcms/translations: 3.63.0
@payloadcms/ui/shared: 3.63.0
react: 19.1.0
react-dom: 19.1.0
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 24.6.0: Mon Jul 14 11:30:40 PDT 2025; root:xnu-11417.140.69~1/RELEASE_ARM64_T6041
Available memory (MB): 24576
Available CPU cores: 14
Activity
cbratschi commentedon Nov 11, 2025
We added a beforeChange hook to set all URLs to undefined. We don't need them in the database either. Our frontend generates the URL and not the CMS. But if you use an external image service or storage provider the URLs might be necessary.
fix: full image urls stored in DB (#15089)
github-actions commentedon Jan 20, 2026
This issue has been automatically locked.
Please open a new issue if this issue persists with any additional detail.