Directus FLows: Item.create and Item.update have different data structure
PrimozJu opened this issue · comments
Describe the Bug
I'm trying to create a Flow that calculate a field (c) based on the information of two other inputed fields(a,b). The diagram looks like this:
When creating a new entry the payload looks like this:
however when making an update to an existing entry, the id is not written in the form of the attribute "key" but the array with one element. The insonsistency is also that the whole actual entry attributes are ommited and: only the fields that were updates are passed which creates further inconsistencies.
This leads to an error where once I'm updating the data I am unable to set the correct ID as it's returned in different formats.
How do we fix this? I've tried filtering (couldn't make it work) and throwing an error in the script which would prompt a read data operation ( in case a or b are missing) and changing the key format however this seems non-optimal.
To Reproduce
To reproduce refer to the schema
The trigger needs to be triggered on items.update and items.create. Create an entry and update it to observe how the key value and attributes are passed
Directus Version
v10.10.7
Hosting Strategy
Self-Hosted (Docker Image)
Database
No response
however when making an update to an existing entry, the id is not written in the form of the attribute "key" but the array with one element.
This is intentional since you can also update multiple items in a single update. https://docs.directus.io/reference/items.html#update-multiple-items
The insonsistency is also that the whole actual entry attributes are ommited and: only the fields that were updates are passed which creates further inconsistencies.
That is consistent with the update action done, updates can be partial (for example a single field) where creating an item will always at least have the required fields. If you want the full entry you will need to fetch that from the database in an update event.
This leads to an error where once I'm updating the data I am unable to set the correct ID as it's returned in different formats.
This is something you will need to check for in your flow/extension. I would personally recommend creating 2 flows one for creation and one for updating (and perhaps a third for delete events as that structure differs too)