Skip to content

Upload collection url and thumbnailURL fields are inconsistently stored in the database #14562

Closed

Description

@jhb-dev

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

https://github.com/jhb-dev/payload-inconsistent-storing-of-upload-url-field

Reproduction Steps

  1. run the Payload app of the linked reproduction repository (blank template without any storage adapters or the payload-cloud plugin)
  2. create a new media document by uploading a file
  3. inspect the URL field in the database (it's not present)
  4. update the media document (e.g. update the alt text)
  5. 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

  1. added
    status: needs-triage
    validate-reproduction
    on Nov 11, 2025
  2. added and removed
    validate-reproduction
    on Nov 11, 2025
  3. cbratschi commented on Nov 11, 2025

    @cbratschi
    Contributor

    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.

  4. removed
    status: needs-triage
    on Jan 12, 2026
  5. github-actions commented on Jan 20, 2026

    @github-actions
    Contributor

    This issue has been automatically locked.
    Please open a new issue if this issue persists with any additional detail.

  6. locked as resolved and limited conversation to collaborators on Jan 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions