Closed (works as designed)
Project:
JSON:API
Version:
8.x-2.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
30 Nov 2018 at 09:35 UTC
Updated:
11 Dec 2018 at 08:21 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
jibranPosting @Wim Leers reply from #3010432-81: Filtering by referenced entity requires ".uuid" to be specified in filter path expression:
First of all thanks for the reply.
This is not a correct statement. Filtering by node serial ID works. The problem is we have the field with the name of 'id'.
It is a whole other discussion that why we feel the need to replace the id value to uuid at the root level. Let's not get into that.
I get the idea behind the fix as mention in the change notice JSON:API filter paths now closely match JSON:API's output structure
My concern is about the 'id' field in the attributes. Maybe we need to update the doc or maybe we need some fix but this filter works for nodes and not for entity_test. Here are my points to revert the fix.
?filter[type]=entity_test--entity_testdoesn't work why are we supporting?filter[id].These are directly translated to
->condition($property, $value = NULL, $operator = NULL, $langcode = NULL)so the fix implemented is a disconnet with that approach.?filter[a-label][condition][path]is describe 'id' is a field on a resource so the fix implemented is a disconnet with that approach as well.jsonapi/entity_test/entity_test/b2765ac0-122b-4087-9820-f8798a318f62but if you are using it in a complex query then for the sake of clarity?filter[uuid]should be used so that we don't relay on JSON:API magic.Comment #3
jibranImproved some wording in the above comments.
Comment #4
wim leersThanks for expanding your explanation/use case, I think I understand you now! 🤓
I think you're saying that the
EntityTestentity type has always had anidfield that contains the serial ID. And you probably have a custom entity type that also has aidfield containing a serial ID. And you probably want that to continue to be the ID exposed in JSON:API and to be able to filter by it.There are a few problems with that:
idexposed for a resource object (every entity is mapped to the "resource object" JSON:API concept) was already using the UUID of the corresponding entityidfield would still show up underattributes, meaning you'd have a resource object like:idviolated the spec (the spec says that the keys underattributesplusrelationshipsare all "fields" and share a common namespace plus there are two reserved keys:idandtype), so now you'd get:(i.e.
attributes.idis omitted)attributes.idis not omitted, using it is just heavily discouraged, by aliasing it with adrupal_internal__prefix. So, really, it looks like this:?filterURL query argument) to not match the structure of the resource object above. It didn't make sense in neither JSON:API 2.x nor 1.x. You should be able to request/jsonapi/entity_test/entity_test?filter[id]=12f8a25b-05cb-4109-a48f-478be68ed8a0, but no, you needed to know the Drupal internals to guess the correct filtering syntax: only/jsonapi/entity_test/entity_test?filter[uuid]=12f8a25b-05cb-4109-a48f-478be68ed8a0worked! This is terrible DX! So we fixed that. Now the filter syntax matches the document structure exactly. Yay, much better UX!/jsonapi/entity_test/entity_test?filter[drupal_internal__id]=12345to not work, even though it should, since that's what matches the document structure exactly. @dagmar discovered this, and reported it at #3015759: `?filter[drupal_internal__id]=ID` does not work: drupal_internal__id should not be converted to uuid when filtering, where it is currently being fixed.That's the whole history. I think the answer to your question is:
To answer your concrete point-by-point criticisms:
drupal_internal__in all JSON:API situations. Before that EFQ condition is added, we map it back to the internal name. I know that doesn't work right now. That's what #3015759: `?filter[drupal_internal__id]=ID` does not work: drupal_internal__id should not be converted to uuid when filtering is fixing right now.I think it's great you're so vocally questioning our choices. I respect your input a lot. But based on prior discussions in the issues I've linked above, where all three JSON:API maintainers jointly concluded this approach was best, I still feel strongly this was and is the right decision. That's why I've taken considerable time writing this comment, to explain every reason for every change in full detail. Hopefully I've convinced you at this point :)
If not, let's set up a call. I want us to get on the same page.
@gabesullice, @e0ipso, looking forward to your thoughts.
Comment #5
jibranThank you for your time and all the work. Let's put it to rest. You(all three of you) clearly have the bigger picture in mind. Maybe I was just bummed that RC2 broke my tests 😛. But I feel a lot better after reading your reply. I understand the reason and you have already made the appropriate doc fixes so it is all good. Thank you again.
Have a very nice day!
Comment #6
wim leersI'm very glad to hear that! ❤️
Comment #7
gabesullice@jibran++!
@Wim Leers++!
I wholeheartedly echo this: "I think it's great you're so vocally questioning our choices. I respect your input a lot."
@Wim Leers got every point right. We made a conscious decision to add a layer of indirection between
filterand EFQ. The corollary is that we removed a layer of indirection between JSON:API's output andfilter. I think the latter better fits with JSON:API's philosophy from the beginning.I think once we finish #3015759: `?filter[drupal_internal__id]=ID` does not work: drupal_internal__id should not be converted to uuid when filtering and [##3017047], the migration path will be fairly straightforward. We won't release 2.0 or another RC until those are resolved.
Thanks again!!!
Comment #8
effulgentsia commentedThe issue summary says that
?filter[nid]=...works. Is that true? It shouldn't. Is there an existing issue to fix that?Comment #9
effulgentsia commentedTo clarify #8, if
nidis renamed todrupal_internal__nidin the resource object, then?filter[nid]should not work and?filter[drupal_internal__nid]should. I'm not entirely clear on why we prefixnidwithdrupal_internal__though, so perhaps an alternate fix is to stop doing that?Comment #10
wim leersCorrect. We have an open bug report with a working patch for that: #3015759: `?filter[drupal_internal__id]=ID` does not work: drupal_internal__id should not be converted to uuid when filtering. That should land soon.
Because we want to discourage the use of alternative identifiers such as Drupal's classical sequential identifiers in favor of UUIDs.
Rationale at https://www.drupal.org/node/2984247