Skip to content

Content collections reference() accepts invalid entry IDs #17322

Description

@smn-cds

Astro Info

Astro                    v7.0.6
Node                     v24.17.0
System                   macOS (arm64)
Package Manager          pnpm
Output                   static
Adapter                  none
Integrations             none

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

In Astro v6 and v7, content references are handled inconsistently for entries whose filenames are transformed into different IDs.

Example referenced entry:

src/content/authors/John-Doe.md

Astro's glob loader slugifies the filename and exposes the entry id as:

john-doe

This means getEntry() expects the slugified id:

await getEntry("authors", "john-doe")

However, a reference value using the original filename casing is still accepted during content validation:

{
  "author": "John-Doe"
}

With a schema like:

author: reference("authors")

Astro transforms the reference into:

{
  "author": {
    "id": "John-Doe",
    "collection": "authors"
  }
}

This reference then does not resolve, because the actual entry id is john-doe, not John-Doe.

As a result, invalid references can pass validation and produce broken or silently missing output at build time.

What's the expected result?

Astro should handle referenced entry ids consistently with the entry ids produced by content loading.

Either:

  1. Content validation should reject non-slugified references.

For example, this should fail validation if the actual entry id is john-doe:

{
  "author": "John-Doe"
}

Or:

  1. Astro should apply the same slugification rules when transforming references.

For example:

{
  "author": "John-Doe"
}

should be transformed into:

{
  "author": {
    "id": "john-doe",
    "collection": "authors"
  }
}

This would make reference() consistent with glob() and getEntry() in Astro v6 and v7.

Link to Minimal Reproducible Example

https://github.com/smn-cds/reproduce-broken-references

Participation

  • I am willing to submit a pull request for this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    - P4: importantViolate documented behavior or significantly impacts performance (priority)pkg: astroRelated to the core `astro` package (scope)triage: fix pendingReporter needs to verify the triage bot fix works

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions