V8-archive: Updates in relational interfaces require required fields

Created on 1 Jul 2019  Â·  8Comments  Â·  Source: directus/v8-archive

When updating an existing item through a relationship, like a one to many, the API requires all required fields to be set, even if they already have a value in the database.

Lets say I have a collection named sections that has a one to many to cards. When I update existing card with id = 4 by sending the following payload

{
  "cards": [
    {
      "id": 4,
      "note": "Test"
    }
  ]
}

the API will return

{
  "error": {
    "code": 4,
    "message": "status: This value should not be blank."
  }
}

even though the field already has a status value in the DB, and it's not a newly created item.

When updating the item through the /items endpoint directly, this problem doesn't occur.

👉 The API should treat updates to existing items in relational fields the same as regular updates.

bug

Most helpful comment

Can you please tell me from where you are passing this payload?

I'm trying to update an item in the collection cards through a one to many field called cards in the collection sections.

PATCH /items/sections/15

{
  "cards": [
    {
      "id": 4,
      "note": "Test"
    }
  ]
}

This should update card number 4 in the cards collection. However, the API returns an error about the required fields missing. This shouldn't happen as the item is being updated and those fields are already filled in the database.

But from the APP the whole object is passing at an update time. So I don't think so this will create the issue.

Not anymore though. From https://github.com/directus/app/pull/1804 onwards the O2M will only send the updated values. The M2M already does this too.

I'll suggest for that we should consider this as a feature request because currently

I disagree. This was meant to work like this all along which makes this a bug.

All 8 comments

This problem currently causes trouble when you have a required field in the junction table of a many to many interface.

This issue also blocks https://github.com/directus/app/pull/1804 from being merged

@rijkvanzanten Can you please tell me from where you are passing this payload?

When updating the item through the /items endpoint directly, this problem doesn't occur.

As you mentioned above I guess you are trying to update from the APP only. But from the APP the whole object is passing at an update time. So I don't think so this will create the issue.

If there has been needing to API support for update only those fields which are passing in the payload; I'll suggest for that we should consider this as a feature request because currently, it does not break any functionality.

Can you please tell me from where you are passing this payload?

I'm trying to update an item in the collection cards through a one to many field called cards in the collection sections.

PATCH /items/sections/15

{
  "cards": [
    {
      "id": 4,
      "note": "Test"
    }
  ]
}

This should update card number 4 in the cards collection. However, the API returns an error about the required fields missing. This shouldn't happen as the item is being updated and those fields are already filled in the database.

But from the APP the whole object is passing at an update time. So I don't think so this will create the issue.

Not anymore though. From https://github.com/directus/app/pull/1804 onwards the O2M will only send the updated values. The M2M already does this too.

I'll suggest for that we should consider this as a feature request because currently

I disagree. This was meant to work like this all along which makes this a bug.

I just updated to 2.3.1 and sort by dragging elements in the related table doesn't work anymore. After I save the record the related items order resets to how it was before.

Wondering if the work in this ticket affected something. Saving changes on O2M seems slower now.

After poking at this issue for a bit I noticed that when I save a record after dragging some elements in a O2M table, the payload the app sends is huge. From there I was able to tell:

The payload includes just the updated O2M field, content in my case, but for each of the elements there's the entire parent object is nested inside content_id (the FK field) which contains a content field on its own (circular joining?) The main object in the payload seems to have the sort values correctly setup (from 1 to 5) but in the nested relations it's passing the initial values.

The second big issue is that for a piece of content with over 20 items in the O2M I get a timeout error (payload too big?).

I could create another ticket but it seems to be related to this.

Screen Shot 2019-07-30 at 7 30 06 PM

Screen Shot 2019-07-30 at 7 30 18 PM

Thank you @ivansf — we'll use your debug info when resolving the related issue: https://github.com/directus/app/issues/1899

This is a priority and is next on our docket.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

carolin-skiply picture carolin-skiply  Â·  51Comments

rijkvanzanten picture rijkvanzanten  Â·  55Comments

ybelenko picture ybelenko  Â·  31Comments

benhaynes picture benhaynes  Â·  31Comments

zeusstl picture zeusstl  Â·  26Comments