V8-archive: Filtering revisions by status does not work

Created on 27 Nov 2019  路  10Comments  路  Source: directus/v8-archive

Bug Report

Steps to Reproduce

Make any revision call with the status query parameter set to published on a collection that has been published and is now in draft (ie https://mysite.com/_/items/articles/2/revisions?status=published )

Expected Behavior

Only the revisions that were published show up in the response

Actual Behavior

Does not do anything, returns all the revisions regardless of status.

Other Context & Screenshots

Also tried with the fields query parameter on the data field, but no filtering is happening. In the context of a website CMS, this is quite a common scenario, as you expect to show the latest published revision of an item if it has been published in the past and is currently in draft because people are working on it

enhancement

All 10 comments

@Bedotech - Filters can be passed in filter param. So,

https://mysite.com/_/items/articles/2/revisions?status=published should be
https://mysite.com/_/items/articles/2/revisions?filter[status]=published

filter param will work with the table field. We didn't provide the support of filters for directus_revisions table as we are not storing any field which can be used as a filter rather than collection and item. Code internally providing this filter so there's no need to provide the filter support.

As per your requirement, you are trying to filter status - which not a field of revisions table but part of a data field JSON and Directus doesn't have a functionality to filter the JSON field.

@rijkvanzanten - thoughts?

@bjgajjar We have a status parameter as well, so the first comment about status vs filter isn't necessarily true. Both should do the same thing.

The API has no way of filtering data that's stored inside the revisions data JSON object, although I do agree that that would be the expected way it should work. Fetching revisions with filter[title]=My Title should return all the revisions where the title of the item that was changed.

I'm a bit conflicted whether to call this a bug or a feature request. On the one hand, I feel like it makes sense to expect the API to behave correctly as the OP mentioned, but on the other hand this is a completely new way of filtering through the data (which is also a custom one-off for the revisions endpoint) by having it search through two JSON columns instead of real MySQL columns. (I'm also wondering if we can even do that performantly enough).

@benhaynes thoughts?

Hmm, interesting. I agree that this is a powerful feature, and it should be added. But as of now, I think this is a Feature Request... as it has not been designed to work this way.

My worry in using the same params (status, filter, etc) on the Revisions endpoint, is that this is a departure from how the API fundamentally works (applying params to the actual table/collection being queried). This endpoint is primarily requesting data from directus_revisions (and a bit of directus_activity), and as Rijk mentioned... fields referenced in the params are for the relational collection (eg: articles).

Perhaps we can look into a dedicated parameter for searching through these JSON fields? That way we maintain some consistency for how our endpoints are expected to work.

To achieve better clarity/visibility, we are now tracking feature requests within the Feature Request project board.

This issue being closed does not mean it's not being considered.

I guess it's a bug in the sense that, according to the documentation, status is a supported query field: https://docs.directus.io/api/reference.html#get-item-revisions Maybe update the doc?

Also do you want me to post it in the feature request? I see it more as being another API endpoint, something like lastPublished which would return the latest revision of an item that was published in the past but is now in draft.

We'll track this issue as a feature request @bendubuisson.

It's a bit confusing, technically, the filter / status etc endpoints work, but they work slightly different then you might expect. It's filtering on the columns in directus_revisions, so you could filter by date of revision, or collection / primary key that was changed. However, you (correctly imo) assumed it would filter on the data that was changed in the referenced item, instead of the directus_revisions collection.

Like @benhaynes mentioned, in order to avoid confusion with the other endpoints, I think we'll have to come up with a new parameter that searches through nested JSON instead of on the column itself. This param might even be useful for other collections where you search through a saved JSON object. Alternatively, we could consider the possibility of making the dot-notation in filter work through nested JSON objects as well, but that might be confusing seeing that's currently used for relational lookup

something like lastPublished which would return the latest revision of an item that was published in the past but is now in draft.

This is an interesting idea too! Lets explore our options with the filtering of nested JSON before jumping ahead for a more specific endpoint. Last updated should also be possible by sorting in reverse order on id, filtered by collection and item, limited to 1, where status in the nested json equals published (or whatever status you want). We can abstract that in the SDKs

Is there any update on this feature/bug? This ticket got closed, but it still does not seem to work.

Filtering for the latest draft and latest published revision is critical for us and stops us from using Directus. But from my point of view Directus is pretty close to support this in comparison to other open source headless CMS.

I am also willing to help developing this feature. But I need someone to help me get started or support me on the way.

I'm also interested in this feature.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

binary-koan picture binary-koan  路  3Comments

HashemKhalifa picture HashemKhalifa  路  3Comments

cdwmhcc picture cdwmhcc  路  3Comments

Nitwel picture Nitwel  路  3Comments

cdwmhcc picture cdwmhcc  路  3Comments