Skip to content

The relation field lookup doesn't tolerate the Drafts #2997

Closed

Description

@emirotin

Link to reproduction

https://github.com/emirotin/payload-lookup-issue

To Reproduce

  • Go to the "AS" collection and create 3 records, titled 1, 2, 3. Do not publish them, let the autosave work
  • Go to the Posts collection, open the existing post, and add try adding a ref to the AS collection
  • All 3 records will be suggested, but all 3 marked as "Untitled"

image

Describe the Bug

The issue here is that the relation lookup field is issuing the API request without specifying the "draft=true" param.
So, it only gets the "published" versions of the docs, which do not contain any data.

This, in turn, seems to be revealing another issue: when a document is created via the API, even in draft mode, its original props are saved to the "real" collection. But when it's created via the UI, the main collection will have an empty record (with only the internal fields, like cratedAt, _status, et.c), and the _versions collection will keep the real data of the draft object.

Payload Version

1.11.1

Activity

  1. added
    status: needs-triage
    on Jul 13, 2023
  2. self-assigned this
    on Jul 17, 2023
  3. DanRibbens commented on Jul 17, 2023

    @DanRibbens
    Contributor

    There is likely something we can improve here, but it isn't the issue as you described from my testing.

    The problem isn't that the relationship is querying with/without drafts. When drafts without autosave, you won't have the issue, it is only when you enable autosave: true where the version data isn't returned the same way as without. That might fix the problem, but I want to understand this better first.

    I don't know why it is, but you get different results if you query a collection that uses autosave with ?drafts=true vs without, though both can return documents with _status: 'draft'.

  4. emirotin commented on Jul 17, 2023

    @emirotin
    Author
  5. jmikrut commented on Jan 8, 2024

    @jmikrut
    Member

    @PatrikKozak let's work together on this one to fix it. I think @emirotin is correct in that we should just make sure ?draft=true is used when fetching relations.

  6. github-actions commented on Sep 7, 2024

    @github-actions
    Contributor

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

  7. locked as resolved and limited conversation to collaborators on Sep 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

status: needs-triage

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions