/jsonapi/user/user?include=roles&filter[roles.uuid][value]=e9b1de3f-9517-4c27-bef0-0301229de792

Drupal8.5.x & Drupal8.6.x
Jsonapi:1.x-dev

error:

"errors": [
{
"title": "Internal Server Error",
"status": 500,
"detail": "Getting the base fields is not supported for entity type Role.",

Comments

caseylau created an issue. See original summary.

lawxen’s picture

Title: filter[uid.roles.uuid][value] get error » filter config entity's base field got error
Issue summary: View changes
lawxen’s picture

Priority: Normal » Critical

I have find dozens of jsonapi endpoint has this problem, so set it as critical

lawxen’s picture

Issue summary: View changes
StatusFileSize
new364.96 KB


Above img show the key part debug information.
Maybe we shouldn't make fieldResolver return roles.entity.uuid, go to sleep :)

wim leers’s picture

Title: filter config entity's base field got error » Config entities cannot be filtered
Priority: Critical » Major

This does not meet the definition of critical. I agree it's a very very important bug though!

lawxen’s picture

I simplify this issue by using the following code:

    $query = \Drupal::entityTypeManager()->getStorage('user')->getQuery();
    $query->condition('roles.entity.uuid', 'e9b1de3f-9517-4c27-bef0-0301229de792','=')->execute();

The jsonapi endpoint equal to executing above code, and the same error occurs.
I'm wondering whether it's a core bug?
@Wim Leers Do you have any idea?

wim leers’s picture

Quoting \Drupal\Core\Entity\Query\QueryInterface::condition()'s docs:

   * @param $field
   *   Name of the field being queried. It must contain a field name, optionally
   *   followed by a column name. The column can be the reference property,
   *   usually "entity", for reference fields and that can be followed
   *   similarly by a field name and so on. Additionally, the target entity type
   *   can be specified by appending the ":target_entity_type_id" to "entity".
   *   Some examples:
   *   - nid
   *   - tags.value
   *   - tags
   *   - tags.entity.name
   *   - tags.entity:taxonomy_term.name
   *   - uid.entity.name
   *   - uid.entity:user.name
   *   "tags" "is the same as "tags.value" as value is the default column.
   *   If two or more conditions have the same field names they apply to the
   *   same delta within that field. In order to limit the condition to a
   *   specific item a numeric delta should be added between the field name and
   *   the column name.
   *   @code
   *   ->condition('tags.5.value', 'news')
   *   @endcode
   *   This will require condition to be satisfied on a specific delta of the
   *   field. The condition above will require the 6th value of the field to
   *   match the provided value. Further, it's possible to create a condition on
   *   the delta itself by using '%delta'. For example,
   *   @code
   *   ->condition('tags.%delta', 5)
   *   @endcode
   *   will find only entities which have at least six tags. Finally, the
   *   condition on the delta itself accompanied with a condition on the value
   *   will require the value to appear in the specific delta range. For
   *   example,
   *   @code
   *   ->condition('tags.%delta', 0, '>'))
   *   ->condition('tags.%delta.value', 'news'))
   *   @endcode
   *   will only find the "news" tag if it is not the first value. It should be
   *   noted that conditions on specific deltas and delta ranges are only
   *   supported when querying content entities.

… it doesn't say this, but AFAIK the %field.entity.%field_on_that_referenced_enitty only works for entities that have the same storage back-end. Content entities are stored in the database by default, config entities are not. So this could never work.

wim leers’s picture

Title: Config entities cannot be filtered » Content entity query following a reference to a config entity cannot be queried
Priority: Major » Normal
Issue tags: +API-First Initiative, +DX (Developer Experience)

IOW: core's configuration entity system does not support this, so neither can JSON API. The entity query system in core should do better checking around this and provide a more informative exception though!

wim leers’s picture

Assigned: Unassigned » wim leers
Issue tags: +Needs tests

I was going to suggest something like is_subclass_of($this->resourceType->getDeserializationTargetClass(), ConfigEntityInterface::class); … but that only works if you're querying a config entity type directly!

Anyway, let's not wait for core to get its act together, we can improve DX today.

wim leers’s picture

Status: Active » Needs review
Issue tags: -Needs tests
StatusFileSize
new1.21 KB

Failing test.

wim leers’s picture

Assigned: wim leers » Unassigned
StatusFileSize
new1.36 KB
new2.54 KB

And fix.

wim leers’s picture

Title: Content entity query following a reference to a config entity cannot be queried » Entity querying config entities does not work, so neither does JSON API collection filtering: provide helpful DX

The last submitted patch, 10: 2959445-10.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

gabesullice’s picture

Status: Needs review » Reviewed & tested by the community

Nice improvement. LGTM.

  • Wim Leers committed da5e9fb on 8.x-1.x
    Issue #2959445 by Wim Leers, caseylau, gabesullice: Entity querying...
  • Wim Leers committed ca998d1 on 8.x-2.x
    Issue #2959445 by Wim Leers, caseylau, gabesullice: Entity querying...
wim leers’s picture

Status: Reviewed & tested by the community » Fixed
e0ipso’s picture

👏🏽

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

rpayanm’s picture

Project: JSON:API » Drupal core
Version: 8.x-1.x-dev » 8.9.x-dev
Component: Code » jsonapi.module

Moving to Drupal core's issue queue.

I'm working on https://www.drupal.org/project/drupal/issues/3122113